Oluphant
11-13-2011, 10:58 AM
Hello everyone, it's me again, hope you can help me once again. I am working on a script that generates multiple spheres and a cube (amongst other things), I want to be able to calculate the distance between the circles and this one cube. Does anyone know how to do that? This is the code I have come up with so far, the pertinent code is on the last 10 lines:
proc makeSpheres( int $amount,string $groupName, string $emitterName, string $particleName, string $sphereName, string $volumeAxisName, string $controllerName) {
global int $amount; //defines how many spheres are created
global string $sphereName; //the name of the sphere
global string $controllerName;// the name of the controller
string $baseSphereName = $sphereName; //this cleans up the names of the objects.
string $baseEmitterName = $emitterName;// if you plug in $emitterName+$i the naming will look something like this: object1, object12, object123, object1234, object12345 etc.
string $baseParticleName = $particleName;
string $baseVolumeAxisName = $volumeAxisName;
for ($i=1; $i<=$amount;$i++)
{
$sphereName = ($baseSphereName+$i);
$particleName = ($baseParticleName+$i);
$emitterName = ($baseEmitterName+$i);
sphere;
rename $sphereName;
select -cl;
//the below script creates an emitter and connects the dynamic to the nParticle
emitter;
rename $emitterName;
nParticle;
rename $particleName;
connectDynamic -em $emitterName $particleName;
//create the volume axis field and connect it to the nParticle
select -cl;
select -r ($baseParticleName+$i);
addAttr -is true -ln "betterIllumination" -at bool -dv false ($baseParticleName+$i);
addAttr -is true -ln "surfaceShading" -at "float" -min 0 -max 1 -dv 0 ($baseParticleName+$i);
string $volume[] = `volumeAxis -pos 0 0 0 -name ($volumeAxisName+"_"+$i) -m -6 -att 0.485 -ia 0 -afc 0.132 -afx 1 -arx 0 -alx 0 -drs 0 -dx 1 -dy 0 -dz 0 -trb 0 -trs 0.2 -tfx 1 -tfy 1 -tfz 1 -tox 0 -toy 0 -toz 0 -dtr 0 -mxd -1 -vsh sphere -vof 0 0 0 -vsw 360 -tsr 0.5 `;
connectDynamic -f $volume[0] $particleName;
// Result: nParticleShape1 //
connectAttr time1.outTime ($volume[0]+".time");
// Result: Connected time1.outTime to volumeAxisField1.time. //
//the below script parents the emitter and particle to the sphere
//therefore when I move the sphere, the emitter moves with it
select -cl;
select ($baseParticleName+$i);
select -add $volume;
select -add ($baseEmitterName+$i);
select -add ($baseSphereName+$i);
parent;
select -cl;
}
//the below script generates random positions within the values specified
for($i=1;$i<$amount;$i++)
{
select ($baseSphereName+$i);
$x = rand(-5,5);
$y = rand(0,2);
$z = rand(-6,8);
move $x $y $z;
select -d;
}
//the cube below will control the sweep attributes change
polyCube ;
rename $controllerName;
move 0 10 0;
select -cl;
for ($i=1; $i<=$amount;$i++)
{
float $spherePositions = ($sphereName+".translateX" $sphereName+".translateY" $sphereName+".translateZ");
float $controlPosition = ($controllerName+".translateX" $controllerName+".translateY" $controllerName+".translateZ");
float $difference = $spherePositions - $controlPosition;
getAttr ("makeNurbSphere"+$i+".endSweep");
if ($difference =< 2) getAttr "makeNurbSphere"+$i+".endSweep" = 180;
else getAttr "makeNurbSphere"+$i+".endSweep" = 360;
}
}
makeSpheres(12,"together","emitter","particle","premier","volume","control");
proc makeSpheres( int $amount,string $groupName, string $emitterName, string $particleName, string $sphereName, string $volumeAxisName, string $controllerName) {
global int $amount; //defines how many spheres are created
global string $sphereName; //the name of the sphere
global string $controllerName;// the name of the controller
string $baseSphereName = $sphereName; //this cleans up the names of the objects.
string $baseEmitterName = $emitterName;// if you plug in $emitterName+$i the naming will look something like this: object1, object12, object123, object1234, object12345 etc.
string $baseParticleName = $particleName;
string $baseVolumeAxisName = $volumeAxisName;
for ($i=1; $i<=$amount;$i++)
{
$sphereName = ($baseSphereName+$i);
$particleName = ($baseParticleName+$i);
$emitterName = ($baseEmitterName+$i);
sphere;
rename $sphereName;
select -cl;
//the below script creates an emitter and connects the dynamic to the nParticle
emitter;
rename $emitterName;
nParticle;
rename $particleName;
connectDynamic -em $emitterName $particleName;
//create the volume axis field and connect it to the nParticle
select -cl;
select -r ($baseParticleName+$i);
addAttr -is true -ln "betterIllumination" -at bool -dv false ($baseParticleName+$i);
addAttr -is true -ln "surfaceShading" -at "float" -min 0 -max 1 -dv 0 ($baseParticleName+$i);
string $volume[] = `volumeAxis -pos 0 0 0 -name ($volumeAxisName+"_"+$i) -m -6 -att 0.485 -ia 0 -afc 0.132 -afx 1 -arx 0 -alx 0 -drs 0 -dx 1 -dy 0 -dz 0 -trb 0 -trs 0.2 -tfx 1 -tfy 1 -tfz 1 -tox 0 -toy 0 -toz 0 -dtr 0 -mxd -1 -vsh sphere -vof 0 0 0 -vsw 360 -tsr 0.5 `;
connectDynamic -f $volume[0] $particleName;
// Result: nParticleShape1 //
connectAttr time1.outTime ($volume[0]+".time");
// Result: Connected time1.outTime to volumeAxisField1.time. //
//the below script parents the emitter and particle to the sphere
//therefore when I move the sphere, the emitter moves with it
select -cl;
select ($baseParticleName+$i);
select -add $volume;
select -add ($baseEmitterName+$i);
select -add ($baseSphereName+$i);
parent;
select -cl;
}
//the below script generates random positions within the values specified
for($i=1;$i<$amount;$i++)
{
select ($baseSphereName+$i);
$x = rand(-5,5);
$y = rand(0,2);
$z = rand(-6,8);
move $x $y $z;
select -d;
}
//the cube below will control the sweep attributes change
polyCube ;
rename $controllerName;
move 0 10 0;
select -cl;
for ($i=1; $i<=$amount;$i++)
{
float $spherePositions = ($sphereName+".translateX" $sphereName+".translateY" $sphereName+".translateZ");
float $controlPosition = ($controllerName+".translateX" $controllerName+".translateY" $controllerName+".translateZ");
float $difference = $spherePositions - $controlPosition;
getAttr ("makeNurbSphere"+$i+".endSweep");
if ($difference =< 2) getAttr "makeNurbSphere"+$i+".endSweep" = 180;
else getAttr "makeNurbSphere"+$i+".endSweep" = 360;
}
}
makeSpheres(12,"together","emitter","particle","premier","volume","control");
