PDA

View Full Version : Color Of Particles Based On Distance


mahigitam
05-26-2009, 12:41 PM
hi frens.this is my first post in cg society.


i used a volume emitter,of size 10 units and a volume field of d same size with field direction inwards.now the particels will be ttravelling from edge to edge..now i want to edit the color of the particles based on the distance.i used a expression which i cudnt succeed..cud u guys plz help me wer i went wrong...
those particles within a range of (0-3units) shud have red color,(3-6units) green color and (6-10units) blue color...actually this problem was in the maya help file(which was done using ramps)...below is my expression list


float $pos=mag(particleShape1.position);
particleShape1.posi=$pos;
if(0<particleShape1.posi<3)
particleShape1.rgbPP=<<1,0,0>>;
else
{
if(3<particleShape1.posi<6)
particleShape1.rgbPP=<<0,1,0>>;
else
particleShape1.rgbPP=<<0,0,1>>;
}

i introduced a new attribute called "posi"which is a data type of "float" and pp(Array) attribute

Cbickel
05-27-2009, 02:06 AM
I would just use a ramp for the color throughout the particles life. Much easier in my opinion.

Derek Wolfe
05-27-2009, 07:40 PM
You want, "to edit the color of the particles based on the distance.", but it is unclear what distance you want to be checking and you have nothing in your expression to check distance.

You can use $distance = mag(positionA - positionB), to get a distance value, you will need to decide what positionA and positionB are, perhaps positionA is the birth position of the particle, and positionB is the current position of the particle.

In any case, once you have a distance value to check you may color your particles using a conditional satement such as;
if($distance < 3)
{
particleShape1.rgbPP=<<1,0,0>>;
}
if($distance >= 3 && $distance < 6)
{
particleShape1.rgbPP=<<0,1,0>>;
}
if($distance >= 6 && $distance < 9)
{
particleShape1.rgbPP=<<0,0,1>>;
}

Hope this is helpful.

Derek Wolfe
05-27-2009, 07:45 PM
Sorry, I was a bit hasty.
you are checking for a distance value, the distance from the origin.

If you change your conditional statements to:

if(particleShape1.posi < 3)
{
particleShape1.rgbPP=<<1,0,0>>;
}
if(particleShape1.posi >= 3 && particleShape1.posi < 6)
{
particleShape1.rgbPP=<<0,1,0>>;
}
if(particleShape1.posi >= 6 && particleShape1.posi < 9)
{
particleShape1.rgbPP=<<0,0,1>>;
}

it will work.

mahigitam
05-30-2009, 06:59 AM
thank u very much derek wolfe,,dat was working perfectly....

it works even when replacing the "posi" attribute with the variable "$pos"...as below

float $pos=mag(particleShape1.position);
particleShape1.posi=$pos;
if($pos < 3)
{
particleShape1.rgbPP=<<1,0,0>>;
}
if($pos >= 3 && $pos < 6)
{
particleShape1.rgbPP=<<0,1,0>>;
}
if($pos >= 6 && $pos < 9)
{
particleShape1.rgbPP=<<0,0,1>>;
}

____________________________________

the mistake i found in my post z that ..the syntax was wrong isnt it?

if(0<posi<3) is wrong and shud be if (posi>0 && posi<3).......right?

once again thank u verymuch as it was my first post in cg society and was replied with no delay...

Derek Wolfe
06-01-2009, 06:07 PM
Glad to help. Yes, the syntax of your original conditional statement may work in other programming laguages (C++), however in mel it does not.

CGTalk Moderation
06-01-2009, 06:07 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.