How to fade particle instancer

Report this File

3a

Views:

64,618

Updated:

Dec 05, 2009

Readership Level:

Advanced

Tags:

instance, particle, fade, mel, script

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.


click for larger version



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)


click for larger version



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)


click for larger version



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.


click for larger version



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)


click for larger version


This is it! Hope i have made this very clear and easy to follow.

CLICK TO SEE A PREVIEW


Alin Sfetcu - VFX Artist

aSfetcu (at) gmail.com

Comments

Dashboard_avatar
Dec 05, 2009
Post id: 9395
Report this comment to moderators [SPAM]

I think there is more simple way, how about using this expression

x_indexPP = int((age/lifespanPP)*10);

to replace your whole if statements.

View Alin Sfetcu's profile
Dec 05, 2009
Post id: 9404
Report this comment to moderators [SPAM]

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.

View rumorsai's profile
Jul 04, 2011
Post id: 14850
Report this comment to moderators [SPAM]

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!

View Alin Sfetcu's profile
Jul 04, 2011
Post id: 14854
Report this comment to moderators [SPAM]

at what line you get that error ? because in theory everything should work

Write a Comment

You must be logged in and have verified your email address to leave a comment. Login or create an account