PDA

View Full Version : MEL script: Can't duplicate nParticles


Oluphant
11-10-2011, 08:25 AM
Hello there interwebs, I have yet another noob question for you. I'd really appreciate some help on this one. I am trying to create a script that generates a given number of spheres with emitters at the center of each sphere. So far I have managed to successfully generate the spheres (with a slightly different code than the one below) and center the emitter but each emitter except the first seems to be missing its nParticles. If you could point me in the right direction I would sincerely appreciate it, here is the code:

proc makeSpheres( int $amount)
{
global int $amount;

for($i=1;$i<$amount;$i++)
{

sphere;
rename premier;
select premier;
select -cl;

emitter;
nParticle;
connectDynamic -em emitter1 nParticle1;
select -cl;

select -r emitter1;
select -tgl premier ;
parent;
}

for($i=1;$i<$amount;$i++)
{
select ("premier"+$i);
$x = rand(-5,5);
$y = rand(0,2);
$z = rand(-6,8);
move $x $y $z;
select ("emitter"+$i);
select -add ("nParticle"+$i);
connectDynamic -em "emitter" +$i "nParticle" +$i;
}

}

makeSpheres(12);

berniebernie
11-10-2011, 11:46 AM
I usually hate using non-basic commands but this works:

proc makeSpheres( int $amount){ for($i=1;$i<$amount;$i++){

string $sph[] = `sphere -n "premier"`;

$x = rand(-5,5);

$y = rand(0,2);

$z = rand(-6,8);

move $x $y $z;

EmitFromObject;

}

}

makeSpheres(12)

Oluphant
11-10-2011, 07:13 PM
Just in case there is someone out there who might be having the same problem I was, here is how I fixed it:

proc makeSpheres( int $amount,string $groupName, string $emitterName, string $particleName, string $sphereName)
{
global int $amount; //defines how many spheres are created
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;

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;
//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 ($baseEmitterName+$i);
select -add ($baseSphereName+$i);
parent;



}

//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,5);
$z = rand(-6,8);
move $x $y $z;
select -d;
}

}


//example of how to call procedure
makeSpheres(2,"together","premier","center","particles");

CGTalk Moderation
11-10-2011, 07: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.