Views:63,040 |
||
Updated:Dec 05, 2009 |
Readership Level:Advanced |
|
Tags: |
||
Maya Versions:4.x, 5.x, 6.x, 7.x, 8.x, 2008, 2009, 9.x, 2010 |
Platforms:irix, linux, mac, windows |
|
Owner: |
Language:English |
|
How to fade particle instancer
(Maya Dynamics Tutorial)
In this tutorial i`ll try to explain how to fade particle instances on a particle basis :). So, here we go :
Duplicate the object which you intend to use as instance 10 times for this example. The number of duplicates are actually steps of fading.
After that duplicate the shader of the object 10 time as well and lower the transparency on every shader 10% lower then the previous one. After that assign the shaders to objects like in the screen shot below.
Create the particle object and prepare it for instancer. Having to make this basic routine every time is boring, therefore i`m using couple of lines of MEL code to add custom attributes and write some basic creation and run-time expression. So here is the code, just select your particle shape and run it.
string $objs[] = `ls -sl -type "particle"`;
string $obj = $objs[0];
addAttr -ln x_indexPP -keyable true -dt doubleArray $obj;
addAttr -ln x_indexPP0 -keyable true -dt doubleArray $obj;
addAttr -ln x_scalePP -keyable true -dt vectorArray $obj;
addAttr -ln x_scalePP0 -keyable true -dt vectorArray $obj;
addAttr -ln x_rotPP -keyable true -dt vectorArray $obj;
addAttr -ln x_rotPP0 -keyable true -dt vectorArray $obj;
setAttr ( $obj + ".lifespanMode") 3;
string $creationExp = `dynExpression -q -c $obj`;
string $runttimeExp = `dynExpression -q -rbd $obj`;
$creationExp = "\\r\\nx_indexPP = (int)rand( 0, 9 );\\r\\n\\r\\nx_scalePP = rand( 0.5, 0.8 );\\r\\n\\r\\nx_rotPP = rand( 360 );\\r\\n\\r\\nlifespanPP = rand( 3, 5 );\\r\\n\\r";
$runttimeExp = "\\r\\nx_rotPP += << rand(10), rand(10), rand(10) >>;\\r\\n\\r";
dynExpression -s $creationExp -c $obj;
dynExpression -s $runttimeExp -rbd $obj;
Open creation expression and replace the row which set the x_indexPP attribute with x_indexPP = 0; This will ensure all particles have no transparency at birth. Then select all 10 objects and create the instancer.
(make sure the instancer attributes are set like in the below screen shot so the custom attributes will be used)
If you hit play you`ll get something like this:
(in this example i have keyed emitter emission rate at frame 0 with value 20 and at frame 20 with value 0 with stepped keys, just to keep the scene readable)
Now I`ll make two new custom attributes:
First attribute is named x_dieAt (be careful this is NOT a PP attribute) and represents a percent value (take values between 0-100) of the lifespanPP, value at which i want my particle to start fading.
Second attribute is x_dieAtPP, which is the calculated value at which each particle i want to start fade, and i`m using it because i have different lifespanPP for every particle.
Next, in the creation expression add the line which calculate x_dieAtPP for every particle.
Now let`s start dealing with run-time expression. This is pretty simply, but a good understanding of the linstep function is needed. Below is the code i`m using to make my particle switch to the next object.
(which is the next step in transparency)
This is it! Hope i have made this very clear and easy to follow.
Alin Sfetcu - VFX Artist
aSfetcu (at) gmail.com
Comments
I think there is more simple way, how about using this expression
x_indexPP = int((age/lifespanPP)*10);
to replace your whole if statements.
It`s not the same thing ... in your case the particle starts to fade as soon as it is born. In my case the particle start to fade only after x_dieAt (%) of its life has passed.
I`ll edit the tutorial to add more information maybe i was not clear enough.
hey I know this may have been a closed session, but is there any updates for Maya 2011? I am noticing that even though some of the naming conventions are the same, i still get an error that says:
// Error: Unknown object type: particle1 //
What I don't understand is, it is the same name, and i even try to rename it a few times, like "particleShape1"...
Anyways, it may serve to help sometime, please keep us posted, thanks!
at what line you get that error ? because in theory everything should work
Write a Comment