View Full Version : control particles by distance from mesh

11 November 2009, 10:45 PM
Hi folks. Heres a question for you. I want to control (kill, move etc) particles based on their distance from the mesh from which they were emitted. I'm currently querying the nearestPointOnMesh node and getting the magnitude of the vector between a given particle and the closest point on the mesh. Like this:

$meshObject = "pSphere1"
$posPP = particleShape1.position;
$x = $posPP.x;
$y = $posPP.y;
$z = $posPP.z;

float $nearestPoint[] = `nearestPointOnMesh -ip ($x) ($y) ($z) -q -p $meshObject`;

float $distance = sqrt( pow(($x - $nearestPoint[0]),2)+pow(($y - $nearestPoint[1]),2)+pow(($z - $nearestPoint[2]),2));

if ($distance > 1.5){
particleShape1.goalPP = 1;}
particleShape1.goalPP = 0;}

But this approach is far too slow with hundreds of thousands of particles. Is there an inherent attribute already in my system which I could use to measure? Or is there a 'standard' approach to this kind of thing?

11 November 2009, 11:13 PM
Hey Andy!

Hows it going, its Ilan.

This is what I would do:

add the "birthPosition" PP attribute from the "per particle attributes list".

Then create a custom float attribute like "distPP".

then plug in the following runtime expression:

particleShape1.distPP = mag(birthPosition - position);

if (distPP > 5){
lifespanPP = 0;

We should meet up again sometime.
Hope all is going well!


CGTalk Moderation
11 November 2009, 11:13 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.