Plugin to detach all elements from object (tree leaf), and convert them to instances?

So I've been looking a way to do this quite a while now, for optimizing imported trees, which have thousands of identical leaves, this would take down the size like hundred times lower - there are scripts to detach elements, and scripts to convert identical geometry to instances (this last one tends to perform strangely, as it instances everything and moves to the original object..) - probably requires optimization and hacking code..

- still the main problem here is that thousand leaves takes soo bloody long to process that it is not a viable option to even use a script, maybe more suitable to a plugin - but I saw nothing similar to that, no plugin detaches elements from object mainly done with scripts, and then converting everything to instances takes that much longer

- all of this mostly for optimizing memory requirements, as I primarily use octane render, not sure if stuff is more optimized for vray, but for some reason, all trees have their thousands of leaves as meshes - instead of instances of a single mesh - maybe max prefers single collapsed mesh instead of instanced objects (also file size would be considerably smaller with instances).. still

- I know, the best way would be to try and create my own, which I will try and do, but what about all those times you need an exact tree and no time to create it

..also where are the resources to try and start coding some max plugins in C? - it looks scary and messy to even do a "hello world" plugin

..BTW just tried the maya built in feature, mesh>separate - it explodes elements under a minute, the maxscript wasn't done after 10 minutes had to force close it.. maya wins here? - max doesn't even have this option available as default..


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robobear510's picture

well the first problem is detaching individual elements

and I was really thinking detaching everything and instancing them and just group, not sure what the performance would be (but showing everything as box migh improve the viewport speed at least) - octane render handles instances pretty well so far

and yes, I've been thinking it still is a bit of a problem to instance each leaf, still clusters of leaves could be a better option, let's say that would be a challenge for the plugin or script - I may try and tackle it with the script, from using existing extract element scripts.. but requires a lot of optimisation, extracting is way too slow for scripts I already tried..
- and also show the optimized data on the viewport like low point cloud data would probably be needed..

- and yes, I did something similar, deleted 80% of a tree canopy, then instanced it back, it isn't really perfect, and is pretty slow just deleting the stuff..
- max is really crappy at handling a lot of poly or vertices - a lot of times when I import zbrush data, max tends to have real difficulties handling, and editing the data is almost impossible slow..

- the thing is octane render handles thousands of instances no problem, but the max viewport is awfully slow just showing wireframe of the objects

.. anyways, I would like to get into experimenting with plugin creation, are there any resources such as scriptspot, whenever I tried searching for info it was really difficult to find a really simple getting started tutorial.. with scripts it took me like a week to figure out a proper script with GUI.. plugin is a totally different beast
- can python scripting help in any way regarding speed performance over just maxscript?

pixamoon's picture


hmm, I'm not sure plugin will help with speed, It will be still max plugin.

But to test speed of your idea I'll go first this way:
1. detach whole canopy of leafs (to one object)
2. use multiscatter (or other scatter tools) to distribute instances on every single leaf
      - Use Regular Pattern           - it will scatter one leaf on each old one
      - Scale Mult: 1.0                      - it will scatter one leaf on each old one
      - Affect Transform
      - Affect Scale                            - it will use old leafs scale and rotation
      - XY Scale: 1.0                         - it will use old leafs scale
3. to move new leafs position I'd change new leaf gizmo
4. and on end you can convert Multicatter to sinlge instanced objects:  Utilities -> More... -> MulticatterTools ->  Generate Objects

If you want to I can send you small scene as sample. Just send me your e-mail.

robobear510's picture

yes, that actually sounds pretty doable..

it is much faster to scatter.. OK, I'll try and play with that idea, but it will probably be very dependant on the scattering plugin - like if I want to upgrade to a different version might cause problems etc.. maybe the max 2015 scatter might do the job..
- great idea actually.. there's probably loads of people having the same problems with huge trees, I think I never came across a really good optimized tree, it's either low poly that's a bit crappy or huge and too detailed
- will keep in mind, thanks for the help :)

you can send to [email protected]
much appreciated, and I'll see if I can make something out of it

pixamoon's picture


Oki, sent you a sample. If this works, and is faster work/render I can do later simple script to replace some % of leafs with new instances... (without exploding old ones)

Try it and let me know.

pixamoon's picture


I'm not really sure if that will be better for render...
If you try to scatter few millions of single grass leafs or any objects it can kill pre-calculation and memory usage in max
That's why is better to scatter groups of grass leafs (as one object) and whole trees

But if you need this script/plugin to just replace leafs and collapsed again... it can be some good idea. Is this what you need ?

I did it once - replacing some amount of leafs with flowers.
But I just detached arounr 40% of leafs as one object, than scatter new instances on every leaf (regular pattern in multiscatter - every leaf has the same uv, so its easy to find a center and normals). and than you can keep scattered instances or attached them to tree...

This way you can also scatter all new leafs on old ones.

Hope it helps a bit...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.