PDA

View Full Version : Using dynamic expression in MEL


H3ro
05-03-2006, 11:27 PM
Hi, I know that I have asked a question which is almost like this one, but maybe this one is harder or that I dont get the consept.

Could anyone please take a look at it and tell me what is worng?
(Btw, I am trying to create a mel script which creates a pinboard)
Thanks in advance

---
{
//for test
file -f -new;

//create the plane, and specify the size of it
//scale
float $scaleX = 10;
float $scaleZ = 10;

//resolution
float $resX = 10;
float $resZ = 10;

string $plane[] =`polyPlane -width $scaleX
-height $scaleZ
-subdivisionsWidth $resX
-subdivisionsHeight $resZ
-ax 0 1 0
-tx 1
-ch 1`;

//find out how many vertex there are on the plane
int $noVert[] = `polyEvaluate -vertex $plane[0]`;

//create the emitter and particleShape
string $emitter[] =`emitter -pos 0 0 0
-type omni
-r 10000
-sro 0
-nuv 0
-cye none
-cyi 1
-spd 1
-srn 0
-nsp 1
-tsp 0
-mxd 0
-mnd 0
-dx 1
-dy 0
-dz 0
-sp 0` ;
string $particl[] = `particle`;
connectDynamic -em $emitter[0] $particl[0];

//modefy the emitter
setAttr ($particl[0]+".conserve") 0;
setAttr ($particl[0]+".maxCount") $noVert[0];
//create a collision event
event -die 0 -count 0 -name PinBoard $particl[0];

//create the expression
dynExpression -s (
"int $noPart = "+ $noVert[0] +";

int $i = 0;
if ("+ $particl[0] +".eventCount[0] > 0)
{
while ($noPart > $i)
{
vector $pos = "+ $particl[0] +".position;
vector $posVert = `xform -q -ws -t "+ $plane[0] +".vtx[$i]`;

if ("+ $particl[0] +".id == ($i))
{
"+ $particl[0] +".position = <<$posVert.x,$pos.y,$posVert.z>>;
}

$i++;
}
}"
)
-rad $particl[0];

}

Stucky
05-04-2006, 07:04 PM
Hi dude. You have some messed up code there. I was trying to debug it, but there are so many errors that I think the best is for you to breakdown the script, and correct the errors. For example, I don't know why you write something like:

"int $noPart = "+ $noVert[0] +";


why the comas at the beginning and end? why the plus signal before and after the variable? You have to do some serious modifications to your script...




-S

H3ro
05-04-2006, 07:44 PM
Well, basicly I have no idea on how to use expression in a MEL command.
In an other script which I have, but I did not make it. In that script is uses the syntax like "+$AttributeFromTheMel+", so if I want to get a value from the MEL part of the script.

Dont know why it dont work in this case. I know I can alos write the Expression in a Proc, using MEL code, and the call it back for the expression, but I am having problems using some of the particle attributes in MEL.

Thanks

Stucky
05-04-2006, 07:54 PM
hummm..I never saw that dude, Sorry if I interpreted it worng. I dont use expressions very often, so I am not the right person to help you. Perhaps someone could jump in and help you out...



-S

H3ro
05-04-2006, 08:22 PM
But again, I can just be confuced and have messed it all up in my head, it would not be the first time...So, I would not put all my money on that I am right...

Ole

H3ro
05-04-2006, 10:21 PM
Here is an update, the old one tryed to use particleShape attributs on a particle node (it tryed to do particle1.id, insted of particleShape1.id) that is not fixed, but still errors left:P

any help would be great.

thanks

{
//for test, create a new scene
file -f -new;

//create the plane, and specify the size of it
//scale
float $scaleX = 10;
float $scaleZ = 10;

//resolution
float $resX = 10;
float $resZ = 10;

string $plane[] =`polyPlane -width $scaleX
-height $scaleZ
-subdivisionsWidth $resX
-subdivisionsHeight $resZ
-ax 0 1 0
-tx 1
-ch 1`;

//find out how many vertex there are on the plane
int $noVert[] = `polyEvaluate -vertex $plane[0]`;

//create the emitter and particleShape
string $emitter[] =`emitter -pos 0 0 0
-type omni
-r 10000
-sro 0
-nuv 0
-cye none
-cyi 1
-spd 1
-srn 0
-nsp 1
-tsp 0
-mxd 0
-mnd 0
-dx 1
-dy 0
-dz 0
-sp 0` ;

//create particle
string $particle[] = `particle`;

//get the particleShape
string $particleShape[] = `listRelatives -s -path $particle[0]`;

//connect particles and emitter
connectDynamic -em $emitter[0] $particle[0];


//modefy the emitter
setAttr ($particle[0]+".conserve") 0;
setAttr ($particle[0]+".maxCount") $noVert[0];

//create a collision event
event -die 0 -count 0 -name PinBoard $particle[0];

//create the expression
dynExpression -s (
"
int $noVert[] = `polyEvaluate -vertex "+$plane[0]+"`;
int $noPart = $noVert[0];

int $i = 0;
if ("+ $particleShape[0] +".eventCount[0] > 0)
{
while ($noPart > $i)
{
vector $pos = "+ $particleShape[0] +".position;
vector $posVert = `xform -q -ws -t "+ $plane[0] +".vtx[$i]`;

if ("+ $particleShape[0] +".id == ($i))
{
"+ $particleShape[0] +".position = <<$posVert.x,$pos.y,$posVert.z>>;
}

$i++;
}
}"
)
-rad $particleShape[0];
}

H3ro
05-07-2006, 10:17 AM
No one know how to solve this one? I have been trying to solve this for a long time, but I am so stuck:(

Thanks in advance

sunit
05-07-2006, 05:01 PM
well, these lines don't need to reference the particle shape:


vector $pos = "+ $particleShape[0] +".position;

if ("+ $particleShape[0] +".id == ($i))

"+ $particleShape[0] +".position = <<$posVert.x,$pos.y,$posVert.z>>


you can use this instead:


vector $pos = position;

if (particleId == ($i))

position = <<$posVert.x,$pos.y,$posVert.z>>


the particle shape already knows that you're querying the current particle position and particleId.

if you're trying to run a loop(?) inside your particle shape, then you should know that the particle expression evaluates once every frame for every particle in the shape. otherwise, i'm not quite sure if you're just trying to constrain the position of particleId == 0 to the plane.vtx[0]....

i would also suggest assembling your expression string this way:

string $s ="";

$s += "int $noVert[] = `polyEvaluate -vertex "+$plane[0]+"\n`;";
$s += "int $noPart = $noVert[0];\n";
$s += "int $i = 0;\n";


where $s will be the particle expression and "\n" sends the string to the next line. mel doesn't know that your string is continuing when you break lines inside a dynExpression command (or any command for that matter) and will generate unterminated string errors with your original script.

-sunit

CGTalk Moderation
05-07-2006, 05:01 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.