View Full Version : LODgroup and particle instancer
04-08-2008, 10:33 PM
If I have objects grouped using an LODgroup, then instance that group using a particle instancer, the LOD values no longer seem to work (all of the meshes are visible at once). Is there a trick to this, or do I need to write a MEL script that handles the swaps?
04-08-2008, 11:12 PM
You'll have to instance each lod obj (not the group) to the instancer...then write some per particle expressions to swap out each obj based on distance to camera using the instancers index number. Hope this makes sense.
04-09-2008, 02:36 PM
Thanks, that makes enough sense to me to get it working. For other people's future reference, here's the slightly longer, but still short tutorial:
1) In your particle instancer, under the Instanced Objects section, add all of your LOD geometry (low, med, high res, etc). This adds the objects to the list and assigns each of them an index.
2) To select which of these objects is displayed for each particle, we need to add a custom per particle attribute to the particle shape node. I called mine LODindex.
3) Then I added an expression to the LODindex attribute (both creation and runtime after dynamics) that calculates how far away the camera is from the particle and then sets the LODindex value based on some distance threshold. Here's the rough code (it assumes you're using the persp camera and threshold distances of 100 and 125 units):
// get the camera position
float $camX = (`getAttr persp.tx`);
float $camY = (`getAttr persp.ty`);
float $camZ = (`getAttr persp.tz`);
// get particle position
vector $part = particleShape1.position;
// calculate distance between them
float $distX = `pow ($part.x - $camX) 2`;
float $distY = `pow ($part.y - $camY) 2`;
float $distZ = `pow ($part.z - $camZ) 2`;
float $dist = `sqrt ($distX + $distY + $distZ)`;
// swap in the correct geometry
if ($dist < 100)
particleShape1.LODindex = 0;
else if ($dist < 125)
particleShape1.LODindex = 1;
particleShape1.LODindex = 2;
4) To make sure the particle system uses the LODindex attribute to change the active instanced object, in the particle shape node, under the instancer section, set ObjectIndex to LODindex.
That should do it...enjoy.
04-09-2008, 02:36 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.