PDA

View Full Version : Specify when to apply turbulence mag


RaGzMaN
11-10-2005, 01:30 PM
Hi there,

Basically what i want to do is control with an expression when to and when not to apply the magnitude of a turbulence field.

What id like to say, is that when the magnitude of a particle is more than 5 away, turn the magnitude of the turbulence off.

What i can think of to do that is something like this:

Create expression for magnitude on the Turbulence.


turbulenceField1.magnitude = 10; //Setting its initial value

$pos = `getAttr particleShape1.position`;
$magpos = mag($pos);

if ($magpos >5)

turbulenceField1.magnitude = 0; //Setting its value if the condition is true



Now the problem im getting is this.


// Error: line 4: Invalid call to "mag". Check number and types of arguments expected by the procedure. //

// Error: line 1: An execution error occurred in the expression expression2. //

// Result: expression2 //

// Error: line 4: Invalid call to "mag". Check number and types of arguments expected by the procedure. //

// Error: An execution error occurred in the expression expression2. //



Many thanks.

DezFX
11-10-2005, 03:08 PM
One thing you may want to try is using getParticleAttr instead of getAttr. The attribute you want to get is worldPosition not position. This will return a float which you will then need to build a vector out of to feed into mag(). Something like this:float $wPos[] = `getParticleAttr -at worldPosition particleShape1`;
vector $pos = <<$wPos[0], $wPos[1], $wPos[2]>>;

Another option is to just use the "maxDistance" attribute on the turbulance field.

RaGzMaN
11-10-2005, 03:22 PM
Hi there, thanks for your reply.

I will try out the getparticleAttr in a bit.

With reference to the max distance on the turb, can you explain how to use that.

I am using Maya 7 and i see in the help it states that areas defined within it will effect the particles. How would i go about setting that up to basicaly tell it if there < mag 5 have no turb but if there > mag5 then wack some turb on them.

thanks again.

DezFX
11-10-2005, 05:49 PM
Select your turbulance field and in the attribute editor or channel box you will see a "Max Distance" attribute. Set that value to 5 and this will limit the field to only affect particles within 5 units.

RaGzMaN
11-10-2005, 06:34 PM
right i follow that much, im not sure im explaining myself propperly.


I want no influence until the mag is past 5.

frogspasm
11-11-2005, 01:19 AM
Set your Turbulence Field>Volume control attributes>Volume Shape to a cube or sphere.
Then check on "Volume Exclusion".
Any particles inside that volume will now be unaffected by the field.

~Mike D.

RaGzMaN
11-11-2005, 07:53 AM
One thing you may want to try is using getParticleAttr instead of getAttr. The attribute you want to get is worldPosition not position. This will return a float which you will then need to build a vector out of to feed into mag(). Something like this:float $wPos[] = `getParticleAttr -at worldPosition particleShape1`;
vector $pos = <<$wPos[0], $wPos[1], $wPos[2]>>;

Another option is to just use the "maxDistance" attribute on the turbulance field.

That worked a treat.

Thanks dude.

Is there a way to deal with turb on a per particle basis. For example if you can understand what im getting at by this script.

When the mag of a particle is > 2 wack some turb on it. When its >2.5 take the turb off.


turbulenceField1.magnitude = 0; //Setting its initial value



float $wPos[] = `getParticleAttr -at worldPosition particleShape1`;

vector $pos = <<$wPos[0], $wPos[1], $wPos[2]>>;

$magpos = mag($pos);



if ($magpos >2)

{



turbulenceField1.magnitude = 50; //Setting its value if the condition is true

}

if ($magpos >2.5)

{

turbulenceField1.magnitude = 0; //Setting its value if the condition is true

}

frogspasm
11-11-2005, 05:22 PM
I'm not sure now to set the turbulence field's magnitude on a per particle basis.
(I'm kind of a newb on particles)

The last bit of code you wrote will just turn the whole turbulence field's magnitude off when the first particle reaches that distance.

But... this is where the "max distance" could come into play.
Turn it on and set it to whatever distance you want the turbulence to stop affecting your particles. Use this with the volume exclusion, and your particles will be affected outside the turbulence's volume, but only inside the max distance value. They'll just keep moving in a straight line outside the max distance volume.

~Mike D.

sunit
11-11-2005, 11:44 PM
do a search for "per particle field" in the help. the first item, under "Tutorials" will tell you how to set per-particle field attrs.

-sunit

frogspasm
11-14-2005, 08:08 AM
Thanks sunit!

Learning something new always makes my day.

So you have to add a (scalar float) general per particle attribute with the nameOfTheparticleShape.nameOfTheField_nameOfTheAttribute (ie: particleShape1.turbulenceField1_magnitude)

Then used this as the runtime expression and it worked:


$magpos = `mag(particleShape1.position)`;

if ($magpos >50)
{
particleShape1.turbulenceField1_magnitude = 100;
}

if ($magpos >60)
{
particleShape1.turbulenceField1_magnitude = 0;
}


~Mike D.

CGTalk Moderation
11-14-2005, 08:08 AM
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.