View Full Version : parenting objects to specific particles
Phlok 09-22-2009, 01:15 PM Hi,
I want to attach some spheres to specific particles using the following expression:
// loop through all particles
(...)
for($i = 0; $i < $pCount; $i++)
{
// if the particleY is above locatorY put it in array
float $pPos[] = `getParticleAttr -at position particleShape1.pt[$i]`;
if($pPos[1] > $locY && rand(0,3) > 1.5)
{
string $spheres [] = `ls -type polySphere`;
int $cnt = size($spheres);
string $newSphere = "glitterBall" + $cnt;
float $rad = rand($radMin, $radMax);
polySphere -n $newSphere -r $rad;
// $newSphere.translateX = $pPos[0];
// $newSphere.translateY = $pPos[1];
// $newSphere.translateZ = $pPos[2];
parent $newSphere particleShape1.pt[$i];
$pInPos[size($pInPos)] = $i;
}
}
The spheres are created but the parent statement seems not to work, as Maya is doing some occult stuff and giving me a warning:
Warning: Cannot parent components or objects in the underworld. //
Is there any means to parent spheres to specific particles, only?
Another question- why does the following not work (Syntax error):
$newSphere.translateX = $pPos[0];
I didn' want to use setAttr/getAttr in the expression but somehow it doesn't work.
Any suggestions are very much appreciated!
|
|
jaydru
09-22-2009, 01:25 PM
i wrote this a while back for baking particles to animated objects, not exactly what your after but might have a few ideas in there for you
/////////////////////////////////////
////bake particle info to objects
/////////////////////////////////////
/*
this will bake out a partcle simulation
to camera facing polygons
creates poly planes for each particle
and animates them based on the particles
information useing creation and
run time expressions
*/
global proc bakeParticleToObjs(){
//get the particle shape node
$shape[0] = nodeType(`ls -sl`);
if ($shape[0] != "particle")
$shape = `listRelatives -s`;
else
$shape = `ls -sl`;
//add scalePP attributes as they will be needed
if (!`attributeExists "spriteScaleXPP" $shape[0]`)
{
addAttr -ln spriteScaleXPP -dt doubleArray $shape;
addAttr -ln spriteScaleXPP0 -dt doubleArray $shape;
}
if (!`attributeExists "spriteScaleYPP" $shape[0]`)
{
addAttr -ln spriteScaleYPP -dt doubleArray $shape;
addAttr -ln spriteScaleYPP0 -dt doubleArray $shape;
}
//create a group node for all the polyPlanes to live in
if (!`objExists "bakedParticles"`)
group -em -n bakedParticles;
//set the in and out tangent types to spline
keyTangent -global -itt spline;
keyTangent -global -ott spline;
//get the current creation and runtime expressions
//creation
string $creationExp = `dynExpression -q -s -c $shape[0]`;
//run time
string $runTimeExp = `dynExpression -q -s -rad $shape[0]`;
///////////////////////
////The Expressions
///////////////////////
//create creation expression on particle shape to create object for each particle
dynExpression -s
($creationExp + ";\
\r\n string $particle = \(\"particlePlane\" + id);\
\r\n string $particleGrp = \(\"particleGrp\" + id);\
\r\n polyPlane -w 1 -h 1 -sx 1 -sy 1 -ax 0 0 1 -cuv 2 -ch 1 -n $particle;\
\r\n group -em -n $particleGrp;\
\r\n addAttr -ln \"Cam_Face\" -sn \"camf\" -at \"enum\" -en \"Off:On:Limit X:Limet Y:Limet Z:\" $particleGrp;\
\r\n setAttr -k 0 -cb 1 ($particleGrp + \".Cam_Face\") 1;\
\r\n parent $particle $particleGrp;\
\r\n parent $particleGrp \"bakedParticles\";\
\r\n float $xyz[] = position;\
\r\n $scaleX = spriteScaleXPP;\
\r\n $scaleY = spriteScaleYPP;\
\r\n $twist = spriteTwistPP;\
\r\n $xyz[0] = ($xyz[0] / 100);\
\r\n $xyz[1] = ($xyz[1] / 100);\
\r\n $xyz[2] = ($xyz[2] / 100);\
\r\n $scaleX = ($scaleX / 100);\
\r\n $scaleY = ($scaleY / 100);\
\r\n setAttr ($particleGrp + \".tx\") $xyz[0];\
\r\n setAttr ($particleGrp + \".ty\") $xyz[1];\
\r\n setAttr ($particleGrp + \".tz\") $xyz[2];\
\r\n setAttr ($particleGrp + \".sx\") $scaleX;\
\r\n setAttr ($particleGrp + \".sy\") $scaleY;\
\r\n setAttr ($particle + \".rz\") $twist;\
\r\n setKeyframe ($particleGrp + \".t\");\
\r\n setKeyframe ($particleGrp + \".sx\");\
\r\n setKeyframe ($particleGrp + \".sy\");\
\r\n setKeyframe ($particle + \".rz\");") -c $shape[0];
//create a run time expression to animate created locators
dynExpression -s
($runTimeExp + ";\n\
\r\n string $particle = (\"particlePlane\" + id);\
\r\n string $particleGrp = (\"particleGrp\" + id);\
\r\n float $xyz[] = position;\
\r\n $scaleX = spriteScaleXPP;\
\r\n $scaleY = spriteScaleYPP;\
\r\n $twist = spriteTwistPP;\
\r\n $xyz[0] = ($xyz[0] / 100);\
\r\n $xyz[1] = ($xyz[1] / 100);\
\r\n $xyz[2] = ($xyz[2] / 100);\
\r\n $scaleX = ($scaleX / 100);\
\r\n $scaleY = ($scaleY / 100);\
\r\n setAttr ($particleGrp + \".tx\") $xyz[0];\
\r\n setAttr ($particleGrp + \".ty\") $xyz[1];\
\r\n setAttr ($particleGrp + \".tz\") $xyz[2];\
\r\n setAttr ($particleGrp + \".sx\") $scaleX;\
\r\n setAttr ($particleGrp + \".sy\") $scaleY;\
\r\n setAttr ($particle + \".rz\") $twist;\
\r\n setKeyframe ($particleGrp + \".t\");\
\r\n setKeyframe ($particleGrp + \".sx\");\
\r\n setKeyframe ($particleGrp + \".sy\");\
\r\n setKeyframe ($particle + \".rz\");") -rad $shape[0];
/////////////////////////////////////////////////////////////////////////////////////
//get range sliders duration and step though every frame
int $frameCounter = (`playbackOptions -q -max` - `playbackOptions -q -min`);
currentTime `playbackOptions -q -min`;
for ($i=1; $i<=$frameCounter; $i++)
{
playButtonStepForward;
}
currentTime `playbackOptions -q -min`;
//reset the expressions to what they were originaly
dynExpression -s $creationExp -c particleShape1;
dynExpression -s $runTimeExp -rad particleShape1;
//simplify anim curves and set scale to 0 when outside lifespan
$bakedParticles = `listRelatives -c "bakedParticles"`;
for ($particle in $bakedParticles)
{
//smplify the baked animations
simplify -timeTolerance 0.05 -floatTolerance 0.05 -valueTolerance 0.01 $particle;
//sets the particles scale to 0 when the particle is out of its lifespan range
$curveX = ($particle + "_scaleX");
$curveY = ($particle + "_scaleY");
$keys[0] = `findKeyframe -which first $curveX`;
$keys[1] = `findKeyframe -which last $curveX`;
setKeyframe -at "scaleX" -v 0 -t ($keys[0] - 1) -ott step $particle;
setKeyframe -at "scaleX" -v 0 -t ($keys[1] + 1) $particle;
setKeyframe -at "scaleY" -v 0 -t ($keys[0] - 1) -ott step $particle;
setKeyframe -at "scaleY" -v 0 -t ($keys[1] + 1) $particle;
keyTangent -t $keys[0] -itt linear -ott step $curveX;
keyTangent -t $keys[0] -itt linear -ott step $curveY;
keyTangent -t $keys[1] -itt linear -ott step $curveX;
keyTangent -t $keys[1] -itt linear -ott step $curveY;
//now simplify the twist animation on the particle palne nodes
$plane = `listRelatives -c $particle`;
simplify -timeTolerance 0.05 -floatTolerance 0.05 -valueTolerance 0.01 $plane;
}
//end proc
}
CGTalk Moderation
09-22-2009, 01:25 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.