Hey people,
Today I needed to write a script for a big project going on right now.
The project requires a TON of trees/houses/accessories to be scattered throughout a huge landscape. The problem, is that most of those things (mainly the trees...but the houses too) are quite high-poly, and there will be HUNDREDS of them (not good when it comes to memory/viewport display!)
So...my idea is to change the resolution of an object's geometry based on its distance from the camera (ie...the farther away an object, the less dense its mesh).
I looked into max's level of detail utility...but it's quite limited, and I also looked into a few other solutions but found nothing satifactory to this project (the main limitation being that all of the objects and trees etc will be PARTICLES, and therefore something like the LOD utility won't work, because it instances geometry).
Sooo.....I wrote some scripts to do the job for me!
The first script is a modifier (which works on anything in any scenario, not just mine...so feel free to try it out!). Basically, it's a modified version of the optimize modifier, in that it optimized your geometry based on the object's position from a specified object (ie...you choose an object, set the distance ranges, and then it'll optimize the geometry based on the distance from the target object you choose).
Here's a video showing an example of what the modifier does:
Here's the script (just run the script and a new "Opitimize by Distance" modifier will show up in the modify panel in the drop down menu):
Now, that's all fine and dandy....but a problem arose. I need all of the trees to be instancable through a particle system (because I don't want to manually place 10,000 trees!)....but if I choose an object (with the above modifier script applied to it) as the "shape instance" object in my pflow, the scripted modifier won't evaluate on each of the particles because they're just instances of the "shape instance" object chosen.
In other words, if I apply my scripted modifier to an object, and then animate a camera and choose the camera as the target object for my scripted modifier....all particles that instance that object will get their "optimize by distance" data from that object, they won't calculate their distance from the camera object individually (that's just how instancing works!)....so I had a dilemma.
Option (a) would be to skip the particle system and just keep all of the trees regular geometry (because there's no way to have a particle emit non-instanced geometry in pflow)....but that would be insane (10,000 non-instanced trees = instance death of max and my computer)
Option (b) would be to setup some kind of system where you manually position a bunch of trees throughout the landscape (anywhere from 10-50), and then have your particles choose their instancing object based on the particle's distance from any one of those manually placed trees. Make sense? Basically, you have a bunch of manually placed trees throughout the scene, apply the scripted modifier to them so they react properly and optimize themselves based on their distance from the camera....and THEN you have each of your emitting particles choose which of those trees is closest to them, and then grab that tree as its instancing object.
Thus, when each of those 50 or so trees adjusts its geometry (based on their distance from the camera), the group of particles around it that have choosen it as their instancing object based on their closeness to it will also get optimized. And voila....after a bunch of testing/scripting/debugging....it works just as planned!!!! (btw...the method I chose to implement the idea i just described was through a script operator in pflow)
Hope I'm not loosing anyone

And if so....here are some video examples:
Here's an example of how I get particles to choose their instancing object based on how far each one is away from the other objects. I've animated the instancing objects to show how the particles change their instancing object based on which one of the chosen instancing objects is closest to them (the particles are shown in green):
Ok...so you can see how all of the particles are changing their form based on their distance from each of the objects (ie...each particle gets its form from the closest object)...so that's working....now all we've gotta do is apply the modifier script to those objects and we'll see that the particles now optimize themselves properly, based on our little workaround we developed.
Check it out! I've made all of the particles the same object to illustrate how this solution would work with a bunch of trees, as in my scenario (there are 500 teapot particles in this example). In the video, the particles are green and the instance objects are blue. If you can imagine that the black sphere is a camera flying around the scene, you can see exactly how this whole effect would work. The further away an object is from the camera...the less dense its mesh gets! Oh...and I also realize that the objects are very flickery right now. The reason for that is that in the scripted modifier settings I turned the max optimization level up really high to prove the point....in a real scenario it would be much lower to not create such a drastic change
Pretty cool huh?