PDA

View Full Version : global procedure - Undeclared variable


ossosso
10-09-2006, 09:48 AM
hi everyone!
I've written a little code, it's quite simple, it create 2 main object (start_control and end_control and other "help locators") with an hermite() function.



//Create Emitter and Particle object//
emitter -pos 0 0 0 -type omni -r 100 -sro 0 -nuv 0 -cye none -cyi 1 -spd 0 -srn 0 -nsp 1 -tsp 0 -mxd 0 -mnd 0 -dx 1 -dy 0 -dz 0 -sp 0 ;
particle;
connectDynamic -em emitter1 particle1;


//Create and rename all 14 locators that I need//
spaceLocator -p 0 0 0;
rename "locator1" "startPos";
spaceLocator -p 0 0 0;
rename "locator1" "startTan";
spaceLocator -p 0 0 0;
rename "locator1" "endPos";
spaceLocator -p 0 0 0;
rename "locator1" "endTan";
spaceLocator -p 0 0 0;
rename "locator1" "startPos_control";
spaceLocator -p 0 0 0;
rename "locator1" "startTan_control";
spaceLocator -p 0 0 0;
rename "locator1" "endPos_control";
spaceLocator -p 0 0 0;
rename "locator1" "endTan_control";
spaceLocator -p 0 0 0;
spaceLocator -p 0 0 0;
spaceLocator -p 0 0 0;
rename "locator1" "noisestart";
rename "locator2" "noisemiddle";
rename "locator3" "noiseend";
setAttr "noisemiddle.translateX" 1;
setAttr "noisemiddle.translateY" 1;
setAttr "noisemiddle.translateZ" 1;
spaceLocator -p 0 0 0;
rename "locator1" "noisestart_control";
spaceLocator -p 0 0 0;
rename "locator1" "noisemiddle_control";
spaceLocator -p 0 0 0;
rename "locator1" "noiseend_control";
setAttr "noisemiddle_control.translateY" 1;

//Create all the Point Constraints//
select -r startPos_control ;
select -add startPos ;
pointConstraint -offset 0 0 0 -weight 1;
select -r startTan_control ;
select -add startTan ;
pointConstraint -offset 0 0 0 -weight 1;
select -r endPos_control ;
select -add endPos ;
pointConstraint -offset 0 0 0 -weight 1;
select -r endTan_control ;
select -add endTan ;
pointConstraint -offset 0 0 0 -weight 1;

//Group the locators//
select -r startPos_control ;
select -add startTan_control ;
group;
select -r group1 ;
rename "group1" "start_control";
select -r endPos_control ;
select -add endTan_control ;
group;
select -r group1 ;
rename "group1" "end_control";
select -r noisestart_control noisemiddle_control noiseend_control ;
group;
rename "group1" "noise_control";

//Create the SetDriveKey between noisestart.middel.end and noise_control//
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateX;
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateY;
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateZ;
setAttr "noisestart_control.translateY" 10;
setAttr "noisestart.translateX" 10;
setAttr "noisestart.translateY" 10;
setAttr "noisestart.translateZ" 10;
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateX;
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateY;
setDrivenKeyframe -cd noisestart_control.translateY noisestart.translateZ;
setAttr "noisestart_control.translateY" 0;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateX;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateY;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateZ;
setAttr "noisemiddle_control.translateY" 0;
setAttr "noisemiddle.translateX" 0;
setAttr "noisemiddle.translateY" 0;
setAttr "noisemiddle.translateZ" 0;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateX;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateY;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateZ;
setAttr "noisemiddle_control.translateY" 10;
setAttr "noisemiddle.translateX" 10;
setAttr "noisemiddle.translateY" 10;
setAttr "noisemiddle.translateZ" 10;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateX;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateY;
setDrivenKeyframe -cd noisemiddle_control.translateY noisemiddle.translateZ;
setAttr "noisemiddle_control.translateY" 1;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateX;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateY;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateZ;
setAttr "noiseend_control.translateY" 10;
setAttr "noiseend.translateX" 10;
setAttr "noiseend.translateY" 10;
setAttr "noiseend.translateZ" 10;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateX;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateY;
setDrivenKeyframe -cd noiseend_control.translateY noiseend.translateZ;
setAttr "noiseend_control.translateY" 0;


//Create the lifespanPP expression//
setAttr particleShape1.lifespanMode 3;
dynExpression -s "int $velocity = 3;\r\n\r\nparticleShape1.lifespanPP = $velocity;\r\n\r\nparticleShape1.position = <<startPos.translateX,startPos.translateY,startPos.translateZ>>;" -c particleShape1;
// Result: particleShape1 //

//Create the particlePP attribute noiseMult and his ramp ramp//
addAttr -ln noiseMult0 -dt doubleArray particleShape1;
addAttr -ln noiseMult -dt doubleArray particleShape1;
setAttr -e -keyable true particleShape1.noiseMult;
arrayMapper -target particleShape1 -destAttr noiseMult -inputV ageNormalized -type ramp;
// Result: arrayMapper1 //
setAttr "ramp1.colorEntryList[0].position" 0;
setAttr "ramp1.colorEntryList[0].color" -type double3 0 0 0 ;
setAttr "ramp1.colorEntryList[1].position" 0.5;
setAttr "ramp1.colorEntryList[1].color" -type double3 1 1 1 ;
setAttr "ramp1.colorEntryList[2].position" 1;
setAttr "ramp1.colorEntryList[2].color" -type double3 0 0 0 ;

//Connect the noisestart.middle.end locator with the ramp //
connectAttr -f noisestart.translate ramp1.colorEntryList[0].color;
connectAttr -f noisemiddle.translate ramp1.colorEntryList[1].color;
connectAttr -f noiseend.translate ramp1.colorEntryList[2].color;

//Create the RunTime expression for particles//
dynExpression -s "float $ampX = 2;\r\nfloat $ampY = 2;\r\nfloat $ampZ = 2;\r\nfloat $freqX = 0.01;\r\nfloat $freqY = 0.01;\r\nfloat $freqZ = 0.01;\r\nfloat $noisestart = 0;\r\nfloat $noisemiddle = 1;\r\nfloat $noiseend = 0;\r\n\r\nvector $startPos = <<startPos.translateX,startPos.translateY,startPos.translateZ>>;\r\nvector $startTan = <<startTan.translateX,startTan.translateY,startTan.translateZ>>;\r\nvector $endPos = <<endPos.translateX,endPos.translateY,endPos.translateZ>>;\r\nvector $endTan = <<endTan.translateX,endTan.translateY,endTan.translateZ>>;\r\n\r\nnoisestart_control.translateY = $noisestart;\r\nnoisemiddle_control.translateY = $noisemiddle;\r\nnoiseend_control.translateY = $noiseend;\r\n\r\nvector $hermite = hermite ($startPos,$endPos,$startTan,$endTan,particleShape1.age/particleShape1.lifespanPP);\r\nfloat $noiseY = ($ampY*noise(time+(particleShape1.particleId*$freqY)))*particleShape1.noiseMult;\r\nfloat $noiseX = ($ampX*noise((time+10)+(particleShape1.particleId*$freqX)))*particleShape1.noiseMult;\r\nfloat $noiseZ = ($ampZ*noise((time+15)+(particleShape1.particleId*$freqZ)))*particleShape1.noiseMult;\r\n\r\nparticleShape1.position = $hermite + <<$noiseX,$noiseY,$noiseZ>>;" -rbd particleShape1;
// Result: particleShape1 //



If you past this code into the script window all works correctly; at the beginning the start_control and end_control are overlying so you have to move one of them. If you click play you can see particles go from start to end_control in a noise way.

If you notice the runtime expression for the particle position, you can see at the beginning this variable:

$ampX-Y-Z ; $freqX-Y-Z and $noisestart.middle.end; they are all float variables and they control respectively the amplitude of the noise in the three axis, the frequency of the noise and the amplitude in the start point, in the middle and in the end point; if you notice for the start and end point values are 0, in fact the particle are fixed to the start and end_control.

Till here all right, nothing wrong.

Now I'd like that the user could insert his valuse for those float variables, and I need help to realize that. This is what I've done:

I saved that code into the script folder of maya using the "herm.mel" name but adding this lines:

global proc herm () {
CODE
}

than into the script editor I wrote "source herm;" and "herm;", and again all works correctly. At last I made this alteration to the herm.mel file:

global proc herm ( float $ampX, float $ampY, float $ampZ.. and so on for all varibles) { CODE--> but from the code I've deleted the "float $ampX=2; float $ampY=2..." lines 'cause I want that values are insert by user }

Then into the script window:
source herm; (all right)
herm 2 3 1.5 etc.; --> I obtein an error, it says that all those float variables are undeclared.

I don't know hot to solve.

I hope I've been clear enough and sorry for the lenght of the post.

Thank you very much for any advice!

Soviut
10-12-2006, 06:02 AM
Have you tried calling the proc using:

herm (1.0, 1.0, 1.0);

Its good form to use proper brackets when calling procedures, and could be the reason your proc isn't running correctly. What its probably doing is passing none of your values since they're not in brackets.

ossosso
10-12-2006, 08:54 AM
Thank you very much Soviut for your answer, I tried, but nothing to do.

If I try with only one varibale (for example with $ampY) I obtein the same message:

// Error: float $noiseY = ($ampY*noise(time+(particleShape1.particleId*$freqY)))*particleShape1.noiseMult;
//
// Error: "$ampY" is an undeclared variable. //

Sigh :(

Robert Bateman
10-12-2006, 04:32 PM
global proc herm ( float $ampX, float $ampY, float $ampZ.. and so on for all varibles) { CODE--> but from the code I've deleted the "float $ampX=2; float $ampY=2..." lines 'cause I want that values are insert by user }

$ampX will only exist within herm, which will have finished executing by the time the expression is run - ergo, $ampX is no longer defined.

Change your string to something like :

$str = "float $ampX=" + $ampX + ";\n" .....

ossosso
10-12-2006, 05:29 PM
mmm...
I'm not able to unerstand where I have to make the change...

You advise me to create a new string variable "$str" and to assign it that kind of value.. but where have I to insert the $str variable?

I thank you very much friend for your help, but I'm sorry 'cause I'm not yet so expert with Mel.. maybe I'd have to begin with something easier :) anyway I'll appreciate a lot if you can be a little more specific.

Thanks.

Robert Bateman
10-16-2006, 11:09 AM
The very last line where you create the dynamic expression. ie, where you deleted $ampX from the text string.

CGTalk Moderation
10-16-2006, 11:09 AM
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.