Painting With Particles
By Eric Keller
copyright 2007 Bloopatone
|
Part Two: Automating the setup using MEL Ok, so that was a bit of fun. Well, actually it was tedious. In this section we'll remove the tedium by creating a MEL script that will create the control attributes and automatically apply all the expressions to any number of particle objects. So in the future you can paint your particles on a surface, select the particle objects, run the script, and then make any adjustments you need to make on the graph editor. This version of the script has no interface, its a just a simple loop. Hopefully in the future I'll have time to create a more elegant version. Step 1: Open a text editor or your favorite MEL scripting environment. Step 2: The first line of the script is our ever popular selection array. string $mySel[] = `ls -sl`; This places all of the selcted objects into a list in the order in which they were selected (ls="list", sl="selected"). This list is contained in the $mySel[] string array variable. The index list starts at 0 and counts up until the array is complete. So if you have three particle objects selected when you run this line $mySel will contain the three particle objects. The first particle object will have an index of 0, the second will have an index of 1, and the third will have an index of 2. Confusing? Not really as long as you remember the list starts at 0. If you want to access the second particle object in the array you would type $mySel[1];. Step 3: OK, we have to back up a little. If you remember, the custom attributes and expressions are applied to the shape node of the particle objects. This means the user has to remember to pick the particle shape nodes in the Outliner before applying the script. This is kind of annoying. It might be nice if the script automatically picked the particle shape node even when the user has selected the particle's transform node. An easy way to fix this is to use the pickWalk command to move down in the hierarchy. This means that if the user selects a bunch of particle objects, the script will move down from the transform node of each particle and select the shape node and then fill the $mySel array with the particle shape nodes. Its not a bullet-proof solution but it should work for now. So lets edit the script so that now the first two lines read: pickWalk -d down; If the user already has the shape node of the particles selected, not to worry, the pickWalk command won't do anything to affect the selection (unless there is something parented to the particle shape node, but that is highly unlikely). Step 4: In the last part of section 1 of this tutorial we created a locator that added a multiplier to the maxSize attribute of the particles. Since this attribute will be referenced in the script we should add it now before starting the loop. We'll also set the attribute to 1. If we leave it at zero it will cancel out the scale of the particles and nothing will happen when we run the script. //create scale mulitplier control on locator. The -at flag sets the attribute type. In this case it is a double which is similar to a float vlaue type. Step 5: Now we'll start the loop which will run once for each object we have selected. To do this we set the loop iterations to the size of $mySel. //start loop to add expressions to the particles Step 6: Next we'll add the expressions. The \r and \n flags just add returns and newlines in the expression eitor which will make it easier to read if we need to edit the expressions.(\t= "tab"). Note that the -c flag and the -rbd flags for the dynExpressions tell maya that the expressions is either "creation" or "runtime before dynamics". //set keyframes on growMe Step 8: Finally we'll just set the particle render type to blobby surface as a mtter of convenience to the user. //set particle render type to blobby surface <<warning - I type like a monkey so if you've followed along writing the script exactly as it appears on this page and you're getting a lot of errors, download this version of the script and compare it to what you've written. I've tested it and it does work>>
part one | part two | part three |