PDA

View Full Version : shatter help, attach particles to objects script question


chrispy2001
12-08-2009, 06:39 PM
I got this script from the shatter help forum. Take all the shattered pieces and puts a particle in the centre of each object attaching it's translation to the respective object. Works brilliant!

//Bind objects to nParticles

string $selection[] = `ls -sl`;
int $n = 0;
float $partPos[];
string $particleList = "nParticle";

for ($sel in $selection){
float $p[] = `xform -ws -q -rp $sel`;
xform -a -ws -t (-1*$p[0]) (-1*$p[1]) (-1*$p[2]) $sel;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $sel;
xform -t $p[0] $p[1] $p[2] $sel;
$particleList = $particleList + " -p " + $p[0] + " " + $p[1] + " " + $p[2];
if(`attributeQuery -node $sel -ex "particleIndex"` != 1){
addAttr -longName "particleIndex" -at "short" $sel;
}
setAttr ($sel + ".particleIndex") $n;
$n++;
}

string $nParticleShape[] = eval($particleList);

for($sel in $selection){
float $w = `getAttr ($sel + ".boundingBoxSizeX")`;
float $h = `getAttr ($sel + ".boundingBoxSizeY")`;
float $d = `getAttr ($sel + ".boundingBoxSizeZ")`;
float $bbox[] = {$w, $h, $d};
float $dim = 0;
if($w>$dim){ $dim = $w;};
if($h>$dim){ $dim = $h;};
if($d>$dim){ $dim = $d;};
$dim = $dim * 0.25;

int $particleIndex = `getAttr ($sel + ".particleIndex")`;

//nParticle -e -attribute radiusPP -order $particleIndex -fv $dim $nParticleShape[1];

string $expr = "float $pos[] = `nParticle -attribute position -order " +
$particleIndex +
"-q nParticleShape1`;\n" +
"translateX = $pos[0];\n" +
"translateY = $pos[1];\n" +
"translateZ = $pos[2];\n" +
"float $vel[] = " +
"`nParticle -attribute velocity -order " +
$particleIndex + " -q nParticleShape1`;\n" +
"if(`currentTime -q` > 1){\n" +
"rotateX = rotateX + ($vel[0]*0.5);\n" +
"rotateY = rotateY + ($vel[1]*0.5);\n" +
"rotateZ = rotateZ + ($vel[2]*0.5);\n" +
"}else{\n" +
"rotateX = 0;\n" +
"rotateY = 0;\n" +
"rotateZ = 0;\n" +
"}\n";


expression -s $expr -o $sel -ae 1 -uc all;
}


The problem is it creates a particle shape nParticleShape1 which is a problem if i want to do more than one of these systems within a scene, being not much of a scripter i want to know if anyone can figure out how to specify the name of the particle shape created?

CGTalk Moderation
12-08-2009, 06:39 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.