Object Spreading Methodsby Nicolas dHaussy, France
Web: http://ndhaussy.free.fr
Using Particle Instancer
Particle instancing is a really fast method. The particle instancer replaces each particle with an object. Obviously, to use the particle instancer, you have to create a range of particles. You can use a particle emitter or the particle paint tool (as easily as the paint geometry tool). Then select your particle shape and create an instancer (Dynamics mode, menu Particles > Instancer options).
Particle paint tool setup |
The particle instancer options will appear. Select an object and add it to the list. Lets tweak parameters (don't touch "cycle" related parameters). I advise you to turn the "Level Of Detail" to "BoundingBoxes" for a better workflow.
Let’s take advantage of using particles... You could apply to the instanced objects complexes particle motion/effects such as using fields and collisions rigid solver (to reach the floor for example). Note that on creating a particle instancer you can set many connections with particles attributes which affect the instanced objects.
How to bake particle instancer? To do so, open the hypergraph, select your instancer node, press Input and Output connections button. Then break the connection between the time node and the particle shape. Your spread instanced objects would keep this position in time.
Animation Driven spreading
We are going to "bake" animation. A kind of solid ghosting effect. First, animate one object the way you want (using any animation helpers you need, such as motion path). Then we will bake animation by simply duplicating the object at its position on the frames required. Also you would have non animated objects correctly placed. ! Last minute note: If you are using Maya 4.5 or higher, use the tool called Create Animation Snapshot.
Animation baked so as to spread the animated object. Example using motion path animation |
You can do it by hand by sliding the time slider and duplicate (CTRL+D) the object at this position in time. Or using this simple script (opens the script editor and executes this script bellow to load this function). Select the animated object(s) you want to bake animation, then is the command line (or in the script editor) type launch the function giving the arguments you want: bakeAnimation (3, 0, 25) for instance. This script does automatically what you would have done by hand... great!
global proc bakeAnimation(int $step, int $startFrame, int $endFrame) {
if($step < 1) { error("bakeAnimation : the step argument must be at least higher than 1.\n"); }
string $selection[] = `ls -sl`;
for($object in $selection) {
for($n = $startFrame; $n <= $endFrame; $n+=$step) {
currentTime -e $n;
duplicate $object;
}
print($object + " animation baked.\n");
}
} |
Melscripting Issue
Here is maybe one of the more interesting ways to spread. You need simple melscripting knowledge’s (or other c-like scripting languages). You must know some basics of melscripting... and especially the random function, duplicate function, transformations (move, rotate, scale) and the loop. Read the comments to understand the scripts steps.
Let’s start code a simple object spreader. Simply duplicate several times the chosen object and place it randomly. The loop repeats several times this same action: returns random value for each axis, duplicate the object; place it with the random values. That is all!
global proc spreadObjects(
string $object, int $duplicateNb, float $Xmin, float $Xmax, float $Ymin, float $Ymax, float $Zmin, float $Zmax ){
for($n = 0; $n < $duplicateNb; $n++) {
// Get location random values float $randomX = `rand $Xmin $Xmax`; float $randomY = `rand $Ymin $Ymax`; float $randomZ = `rand $Zmin $Zmax`;
// Duplicate and place it randomly string $duplicatedObject[] = `duplicate $object`; move $randomX $randomY $randomZ $duplicatedObject; } print($object + " duplicated and randomly placed " + $duplicateNb + " times.\n");
} |
To use this procedure/function, first execute it in the script editor or source the melscript file, then call the function from the command line. For instance, you can use this function by typing spreadObjects("myObject", 30, -10, 10, -10, 10, -10, 10). This tool we've just coded is very useful and easy to use.
spreadObjects() function used to place randomly 60 sheeps. |
|
|
|