The Eiffel Tower project

OSM trees

I didn't speak about the trees I downloaded with the addon yet. This is how they look:

The addon uses one default tree mesh consisting of 65 verts. By downloading multiple trees you'll get linked data of course - i.e. downloading 100 trees still remain 65 verts, not 6.500. Helps to keep resources low.

I think the trees are quite charming but anyway would have preferred using my own shapes.

Paris (resp. whole France) is divided into Arrondissements, and I followed this structure for my trees as well, parenting them to "Arrondissement Empties".

 

As you may remember I used group instances for my former greenery. So I thought about a possibility to replace the downloaded tree objects with empties, then use some kind of random selection (for different tree types) and apply group instances to the selections.
(In case you can't remember: Blender offers a really smart solution to copy attributes from one active object to multiple selected ones; I described it here.)

This turned out to be a bit tricky. The downloaded trees differ in size and rotation, and I planned to keep this information as well. Simply speaking: converting the tree meshes to empties, because this should as well have saved the object's attributes.
Unfortunately this seemed to be impossible - there's no way to convert (mesh) objects to empties in Blender.

It took me some time to come along. Anyway I think this is a good example for working with Blender: defining the problem, split it into small logical unions, then solve the problem by solving the small sub-problems one by one... and of course learning a lot doing so.
Therefor I'll describe my procedure quite detailled here - might be interesting for some of you, and the others hopefully won't curse me for that ;-)

 

The problem seemed to be simple: Having thousands of tree mesh objects I wanted to replace them through empties. Each empty of course should be at the same place than the original object and - furthermore - should inherit its properties (scale, rotation).
Talking about nearly 220.000 tree objects this had to be done somehow automatically.

Simply converting them wasn't possible - as said. But I had some ideas.

For preparation I copied and pasted all the tree objects into a blank 2.79 Blender file (unfortunately I'm not too happy with the new Blender having sorted out layers, groups a.s.o., all being "Collections" now. And Blender 2.79 crashes when trying to open a 2.8+ file, but copying and pasting works like a charme).
I merged one tree's vertices at its origin (having linked data all the other trees followed). This gave me a bunch of objects all consisting of exactly one vertex (in the end this turned out to be unnecessary, but let me report step by step).

 

First attempt: Dupligroups.

For those of you being not familiar to that you may look up Google for "Dupligroup" or "Duplication" - although this is special for the old Blender versions. It's called "Instancing" now.
"Dupligroup" simply speaking means attaching one group instance to multiple given objects.

That seemed to be a good idea. So I appended one of my lollipop groups (remember? Look here) into the file and attached it to all the single-vert tree objects.

Next of course I wanted to get rid of the original data, having the group instances (so to say) "stand alone".
There's a hotkey for that: it's called "Make Duplicates real" (Ctrl + Shift + A).
Unfortunately this operation didn't only separate the duplicated group instances from their originally linked objects (which I planned to do) but also converted the group instances to adequate mesh objects (which was producing millions of verts and of course wasn't what I wanted to achieve).

Shortly speaking: I had develloped a quite complicated workaround to replace (similar) meshes through (similar) other ones. I had known easier ways for that before... ;-)

 

Second attempt: Particles.

... especially talking about the "Hair" option. I knew it's possible to have some hair being emitted from an object, and I knew it's as well possible to replace single "hair strings" through group instances. Lastly I knew that particles could be applied afterwards - just like any modifier.

So the plan was to set up a particle system that attached one of my "lollipop" group instances to every vertex, then apply the system and delete the original mesh.

Of course I didn't want to spend days applying particle systems to each single tree object (which you may remember being Single-vertex-objects now); therefor I joined all the tree objects to one and set up the particle system.
I was aware that doing so I'll loose all the transformation data (individual tree sizes a.s.o.), but thought that in the end this would be an acceptable price to pay.

Worked fine, but unfortunately gave me the same result: each tree (so to say each "hair") being converted to a solo-standing mesh.

 

Third attempt: Python.

Honestly speaking I wasn't too engaged. I'm working with Blender for several years now (guess I reached the state of being "no more total noob" ;-), but had absolutely no experiance concerning Python.

Of course writing scripts or even complex software is familiar to me - I used to work with e.g. PHP for ages... but never had a look at Python.

There's a reason for programming languages are called "languages": vocabulary might differ, but the basic logic in most cases is quite alike. And I was aware of the basic logic of solving my problem:

  1. Loop through all tree objects
  2. For each: capture position, scale and rotation and store into variables
  3. For each: Place an empty, apply variables' values to the empty,
  4. then delete original object.

That's all. I should get it solved. Only challenge seemed to be learning the Python vocabulary.

And indeed I got it, although it might have been some kind of "word-by-word-translation". Took me half a day to write, does its job, but certainly very slow and ineffective.
(If you're interested in the script - just leave a post, but I think: those of you being familiar to Python would need just a few minutes to write something that's ten times as good.)

 

4th attempt and solution: Again Dupligroups.

While I sat there, staring at my screen, waiting fo my Python script to come along with the next bunch of tree objects, I was re-thinking the problem over and over. Somehow like this:

And so I did. Worked like a charme! That's it step by step:

  1. Place an empty at 0/0/0
  2. Convert to group (Ctrl + G) and name it somehow "Empty Group".
  3. Then select one tree object being active,
  4. select all the other tree objects (easily done: "Select" -> "Select by type" -> "Mesh"; assuming you've started with a blank scene just like me, otherwise this will select some unwanted objects additional)
  5. in Properties panel / Duplication choose "Group".
  6. Below select the Empty Group
  7. Right mouse click twice to copy duplication and group to all selected tree objects
  8. Ctrl + Shift + A to make duplicates real
  9. Lastly delete all the tree meshes.

Only problem: Doing so I lost the parent/children relationship between the "Arrondissement Empty" and the tree empties, but doing it separate for each Arrondissement and parenting new solved the problem.

 
 
 
 

As a result I now have

Lots of stuff, of course. Should be ok to cover all future eventualities ;-)

 
 

next   

 
 
 

Leave a comment

Attention! Comments including hyperlinks or mail adresses within the "Message" field will be automatically spammed.