PDA

View Full Version : tweak per particle goal strength?


EightBit
11-14-2011, 10:12 PM
I have an animation with particles flowing through a Volume Axis Field, and when they reach the end, they stick to geometry which is set as a goal. I have the various attrs keyframed to get the system working. The goal strength is activated and increased as the particles exit the Volume Axis, but it pulls the last few hundred particles out a bit too quickly. Is there a way to prevent the particles' individual goal weights from increasing until they are out of the Volume Axis (probably an expression)? It could probably be based on particle position if nothing else - but I have no experience w/particle expressions...
Thanks.

Calibrix
11-15-2011, 07:01 AM
You can trace the connection from the volume axis field into your particle shape. It'll be named something nondescript like "input01" or something. That is the force that the field is applying to you particles. You can then write an expression that has an if statement:

if (input01 > 0) {
goalPP = 0;
} else {
goalPP = 1;
}

berniebernie
11-15-2011, 12:36 PM
(particleShape1.inputForce[n])

use the numeric display of particles with a scalarPP that reads the inputForce to see how they change.

EightBit
11-15-2011, 03:46 PM
Thanks.
I'm almost there, but after adding the expression, the particles go straight to the goal at the beginning of the simulation.
I have both 'Magnitude' and 'Along Axis' on the vol axis keyed, and they both are above 0 when the sim starts.
I tried adding a few frames to the expression to be sure that the particles are all influenced by the vol axis, but they still jump to the goal immediately:
if ( (pharma_prtclesShape2.inputForce[0] > 0)&& (time < 25) ) {
pharma_prtclesShape2.goalPP = 0;
} else {
pharma_prtclesShape2.goalPP = 1;
}
@Bernie:
When I set "Render Type" to numeric, I get a thick block of numbers. How do I limit the numbers to pharma_prtclesShape2.inputForce[0]?
Thanks.

berniebernie
11-15-2011, 05:25 PM
I don't really know how to use the radial field but here's a little test I did using a 'switch' (because your particles need to be affected by the field before they are goal'ed)

You might get ideas looking at the xpression editor

http://mlkdesign.online.fr/dump/t.ma

EightBit
11-29-2011, 03:39 AM
Hey Bernie:
Thanks for the scene, but I'm still stuck. In your example scene, the particle numbers remain 0.00 during the whole sim (rather than being set to the inputForce), so something is probably not quite right.

I added a per particle attr named 'Switch' and adapted your code as a 'Runtime after Dynamics' expression, but the switch is not being set.
Not sure how to troubleshoot this, but when I stop the simulation and test the value of the 'Switch' attr, I get a list of zeros:
cmds.getAttr('forensicsParticleShape.Switch')
# Result: [0.0, 0.0, 0.0 ...Another attempt at testing the code was to set the input threshold high (1000) for activating the goal. My runtime expression is:
if(forensicsParticleShape.inputForce[0]>.1){ forensicsParticleShape.Switch = 1;
}
if(forensicsParticleShape.inputForce[0]<1000 && forensicsParticleShape.Switch==1){
forensicsParticleShape.goalPP = 1;
}We're probably close.
Another approach would be to test the distance to the goal object and then set the weight to 1 when it is close enough, but I don't know how to do that either...
Thx.

EightBit
11-29-2011, 05:36 AM
I'm closer:
vector $goal0Pos=forensicsParticleShape.goalWorldPosition0PP;// Get the WPos of each goal for each particle vector
$pos=forensicsParticleShape.position; // the particle's positionPP

// When the particle is close to the goal (out of the volume axis), set the goal weight to 1:
if (abs($pos-$goal0Pos)<0.1) forensicsParticleShape.goalWeight0PP = 1;But when the first particle is within the range, the goal is set to 1 for all the particles...

Parv
11-29-2011, 07:05 AM
You can add a locator at the place where your particle leave the field and query the position of the particles with respect to that locator. If they go beyond locator, they get a GoalPP of 1 (or any number above 0) but if they stay behind the locator, then they maintain a value of 0 in Goal PP.

Lets say you have the particle travelling in the x direction in world space. And you have a volume axis field pointing in the x direction to push the particles. So you can place a locator at the end of that volume axis field somewhere close to where the particles are exiting the field and in GoalPP write this expression in runtime :

vector $pos =particleShape1.position;

if ($pos.x > locator1.translateX)

particleShape1.goalPP = 1;

else
particleShape1.goalPP = 0;


also in the creation expression add:


particleShape1.goalPP = 0;


So they are born with a zero goalPP.


Hope this helps... : )

EightBit
11-29-2011, 03:44 PM
Hey Parv
Thanks a lot! That does exactly what I need!
For the record, it took awhile for the particles to settle onto the goal, so I set the goalWeight0PP to 1 in the creation expression and then they stick to the goal immediately after passing the locator.

ParticleShape.goalPP = 0;
ParticleShape.goalWeight0PP = 1;

EightBit
12-16-2011, 08:49 PM
For the record, I found that using the distance between the particle and goal is more flexible than using a reference object for this task.
Adjust $distanceToGoal as needed.
Code:
Creation Expressions:
partcle2Shape.goalWeight0PP=1;
partcle2Shape.goalPP = 0;

Runtime before Dynamics Expressions:
vector $goalPosition = <<goal.translateX, goal.translateY, goal.translateZ>>;
vector $particlePosition = partcle2Shape.worldPosition;
$distanceToGoal = abs(mag($particlePosition-$goalPosition));
if ($distanceToGoal < 1) partcle2Shape.goalPP = 1;

CGTalk Moderation
12-16-2011, 08:49 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.