PDA

View Full Version : Assigning a goal per particle - MEL problem?


gattu_marrudu
06-09-2009, 08:41 AM
Hi,
I am building a particle system with a fixed number of particles which should move each towards a specific goal.
So I have i.e. a 12 unit particle object, and 12 goals attached to it. Particle 0 should go to goal0 and so on.
I wrote this creation script:

flowers3_partShape.goalPP = 0; //Reset goal weights
for ($i=0; $i<12; $i++) {
$gws = "flowers3_partShape.goalWeight"+$i+"PP"; //Goal weights for each object
if (particleId == $i)
$gws = 1;
}

But it does not seem to work. I am sure it is a syntax issue.

Using setAttr with per particle attributes does not help either:

flowers3_partShape.goalPP = 0; //Reset goal weights
for ($i=0; $i<12; $i++) {
$gws = "flowers3_partShape.goalWeight"+$i+"PP"; //Goal weights for each object
$goals = getAttr ($gws);
$goals[$i] = 1;
setAttr $gws $goals;
}
// Error: 'flowers3_partShape.goalWeight0PP' is not a simple numeric attribute. Its values must be set with a -type flag. //


Is there a way I can do this without assigning each value manually?

Thanks

gm

Sagroth
06-09-2009, 08:17 PM
I don't know what it is you're doing, maybe there're better ways than to create that amount of goals, but anyway... In your case you should write smth like this in creation expr:

int $id = particleId;
string $goal = ("goalWeight" + $id + "PP");
particle -e -id $id -at $goal -fv 1.0 particle1;

Wick3dParticle
06-12-2009, 12:29 AM
Heyo,

So I took a quick stab at it. I basically wrote a script to automate everything for you...
Its fairly simple. Just create the objects that u want your particles to be goaled to, and your particle shape. You can use an emitter too, the script will limit the particle count to the object count for you. Select the Particle FIRST and shift select your objects - then run the script. igParticlePerObj(your goal weight);



source AEdynObjectGoalWeightNew;
global string $mySel[];
global string $particleNode;
global string $particleShape[];
$mySel = `ls-sl`;
$particleNode = $mySel[0];
stringArrayRemoveAtIndex(0, $mySel);
$particleShape = `listRelatives -shapes $particleNode`;
eval("setAttr " + $particleShape[0] + ".maxCount " + size($mySel) + ";");

global proc igSetGoals(){
global string $mySel[];
global string $particleNode;
for($each in $mySel){
goal -w 0.5 -utr 0 -g $each $particleNode;
}
}

global proc igSetWeightPP(){
global string $mySel[];
global string $particleNode;
global string $particleShape[];
int $i;
for($i = 0; $i<size($mySel); $i++){

addPerParticleGoalPointAttr $particleShape[0] $i Weight doubleArray;


}
}

global proc igAssignGoalPP(float $myGoalWeightPP){
global string $mySel[];
global string $particleNode;
global string $particleShape[];
int $i;
string $dynExpression = "dynExpression -string \"";
string $tagToExpr;
for($i = 0; $i<size($mySel); $i++){
$tagToExpr += "particle -e -or " + $i + " -at " + "goalWeight" + $i + "PP" + " -fv " + $myGoalWeightPP + " " + $particleShape[0] + ";";

if($i<(size($mySel)-1)){
$tagToExpr += "\\" + "r" + "\\" + "n";
}
else{
$tagToExpr += "\" -runtimeBeforeDynamics " + $particleShape[0] + ";";
}}
eval ($dynExpression + $tagToExpr);
}


global proc igParticlePerObj(float $myGoalWeightPP){
igSetGoals();
igSetWeightPP();
igAssignGoalPP($myGoalWeightPP);
}

igParticlePerObj(.5);



Hope this helps,

~Ilan

gattu_marrudu
06-12-2009, 07:21 AM
Thanks a lot! I will try it out.
I am used to PHP scripting for web and, compared to that, MEL looks so primitive...

ah-fx
06-16-2009, 07:47 PM
The draw back to mel is it is not an object orientated language.

so the following wont work:

$gws = "flowers3_partShape.goalWeight"+$i+"PP"; //Goal weights for each object

$gws = 1;

your assigning $gws as a string and then over writing it as an integer.

You have the right idea with setAttr
$gws = "flowers3_partShape.goalWeight"+$i+"PP"; //Goal weights for each object
$goals = getAttr ($gws);
$goals[$i] = 1;
setAttr $gws $goals;

but you're trying to miss match your array variable,

I think this is what you're after:

string $goals[];
if(particleId == $i) {
$goals[$i] = 1;
setAttr $gws $goals[$i];
}

CGTalk Moderation
06-16-2009, 07:48 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.