Outline
This small procedure measures the distance in between two transforms. In this particular case two individual particles, but with the same workflow can be used for say for joints or locators. You could use the information this procedure provides to make your particles �do� something. Say you want you particles to die when they come within a certain distance from each other; or you want them to explode into more particles once the are 15 units away from each other. The sky is the limit.
Pseudo code:
(Pseudo code is a sort of half English, half MEL language you use to do a drop down design, to order and categorize your thoughts, before you actually start writing the code)
Notes:
Code
This small procedure measures the distance in between two transforms. In this particular case two individual particles, but with the same workflow can be used for say for joints or locators. You could use the information this procedure provides to make your particles �do� something. Say you want you particles to die when they come within a certain distance from each other; or you want them to explode into more particles once the are 15 units away from each other. The sky is the limit.
Pseudo code:
(Pseudo code is a sort of half English, half MEL language you use to do a drop down design, to order and categorize your thoughts, before you actually start writing the code)
1. Get the world position of each particle using the getParticleAttr command and store the result in a variable (in casu a float array)
2. Get the indivual elements out of the array and substract them from each other
3. Use the mag command to get the length (distance) of those 3 values.
(=The �vector� that results from the subtraction of the 2 float arrays that hold the position of the particles)
Notes:
1. I know what you are thinking and it is indeed a bit weird that I need use a float array and not a vector to store the position of a particle. But in the command reference it states that the return value of getParticelAttr is a float array.
2. Arrays are zero-based, so always remember the first element in array is [0]. So, also here, with the declaration of $distancePos.
3. Read the docs on mag to find out the math behind it. The normal (Using Maya) docs give a better explanation then the MEL command reference. Basically, mag returns the magnitude of a vector. This is the length of the vector.
4. Obviously this code could be made more dynamics by working with selected items, instead of specific particles.
Code
//First, create two particles with the particle tool
//Declare the variable
// When expecting a return value, you need to
// explicitly declare the data type of the procedure,
// as you do with variables. In this case a float
global proc float getPartDistance()
{
//Get the disctance of both particles
//and store them in a variable
float $part1Pos[] = `getParticleAttr -at position particle1.pt[0]`;
float $part2Pos[] = `getParticleAttr -at position particle1.pt[1]`;
//Declare a new variable that holds the
// results (xyz) of the substarction of
//the position of both particles.
float $distancePos[];
$distancePos[0] = $part1Pos[0] - $part2Pos[0];
$distancePos[1] = $part1Pos[1] - $part2Pos[1];
$distancePos[2] = $part1Pos[2] - $part2Pos[2];
// Use mag to get the length of those 3 values
// This very conveniently also converts 3 (vector) values in 1 (float).
float $distance = `mag <<$distancePos[0], $distancePos[1], $distancePos[2]>>`;
//return the result
return $distance;
}
//Declare the variable
// When expecting a return value, you need to
// explicitly declare the data type of the procedure,
// as you do with variables. In this case a float
global proc float getPartDistance()
{
//Get the disctance of both particles
//and store them in a variable
float $part1Pos[] = `getParticleAttr -at position particle1.pt[0]`;
float $part2Pos[] = `getParticleAttr -at position particle1.pt[1]`;
//Declare a new variable that holds the
// results (xyz) of the substarction of
//the position of both particles.
float $distancePos[];
$distancePos[0] = $part1Pos[0] - $part2Pos[0];
$distancePos[1] = $part1Pos[1] - $part2Pos[1];
$distancePos[2] = $part1Pos[2] - $part2Pos[2];
// Use mag to get the length of those 3 values
// This very conveniently also converts 3 (vector) values in 1 (float).
float $distance = `mag <<$distancePos[0], $distancePos[1], $distancePos[2]>>`;
//return the result
return $distance;
}
Page 1 of 1
Author: kmannens
Submitted: 2006-02-20 16:56:05 UTC
Tags:
Software: Maya
Views: 29,283
Related Items
-
The Elder Wand 3D Model
$25.00 (USD) -
The Resurrection Stone 3D Model
$20.00 (USD) -
The Metaphone Model 3D Model
$29.00 (USD) -
csScale Measure Distance Tool and Speed Display 1.0.0 for Maya (maya script)
$20.00 (USD) -
The Stephenson Rocket Locomotive 3D Model
$99.00 (USD) -
F/A-18E 3D Model
$139.00 (USD) -
A-380 Fedex 3D Model
$120.00 (USD) -
Blonde woman in jeans and sweater - aXYZ design - AWom0004-CS / Rigged for 3D Max + Character Studio 3D Model
$49.00 (USD) -
A-380 China Southern 3D Model
$120.00 (USD)