PDA

View Full Version : Expression Help


JamSession
03-17-2006, 10:31 PM
First I am a total Rookie when it comes to mel and expressions

I am trying to create a global procedural for camera shake

I keep getting a syntax error on my expression line.



expression -s ($cam[0] + ".rx = $cam[0] + ".camShakeAmount * (noise($cam[0] + ".camShakeSpeed * time));




Full Code

global proc jamMakeCamShake ()
{
// get the selected objects
string $cam[0];
$cam = `ls -sl`;

// make sure there are objects selected
if (size($cam) == 0)
error ("You need to select a camera.\n");

//Add The Camera Shake Speed Attributes
addAttr -ln camShakeSpeed -at "float" -min 0 -dv 1 $cam[0];
setAttr -e -keyable true ($cam[0]+".camShakeSpeed ");

//Add Camera Shake Amount Attributes
addAttr -ln camShakeAmount -at "float" -min 0 -dv 1 $cam[0];
setAttr -e -keyable true ($cam[0]+".camShakeAmount ");


//Create the expression for rx
expression -s ($cam[0] + ".rx = $cam[0] + ".camShakeAmount * (noise($cam[0] + ".camShakeSpeed * time));
}
//end of script

Any Help is greatly appreciated.

Bonedaddy
03-17-2006, 11:04 PM
Try this. Your expression was not appropriately delineating which parts were variables.

expression -s ($cam[0] + ".rx = " + $cam[0] + ".camShakeAmount * (noise(" + $cam[0] + ".camShakeSpeed * time))");

Bonedaddy
03-17-2006, 11:09 PM
I'd also like to point out that most camera shake is done in compositing, so unless you need really specific controls on it, and are willing to take the hit to both your render times and your turnaround speed, I would advise against it.

JamSession
03-17-2006, 11:23 PM
Try this. Your expression was not appropriately delineating which parts were variables.

expression -s ($cam[0] + ".rx = " + $cam[0] + ".camShakeAmount * (noise(" + $cam[0] + ".camShakeSpeed * time))");

Thank you very much, I will give that a try.

Can you explain in basic terms what you mean by delineating?

I am a compositor, but it is a group project, and the person we designated as the compositor doesn't know too much. So we are trying to do as much straight rendering as possible. That way she can't mess up too much

ajk48n
03-18-2006, 01:12 AM
Anytime you are making an expression, you need everything in quotes except for variables. If you put variables in quotes, the variable name will get passed, instead of the value.

For example:

$variable = "my"
expression -s ($variable + "_test")

The string that gets passed here is:

"my_test" (without the quotes)

If you have
expression -s("$variable + _test")

The string that gets passed is:
"$variable + _test"


Anytime you want to pass the value that is in the variable, make sure it is not within quotes.

Hopefully this helps

Bonedaddy
03-18-2006, 02:02 AM
Can you explain in basic terms what you mean by delineating?

What you're doing with the command you wrote is passing a string argument to the expression command. That string is the expression you want created. You have a variable in there, the camera name, which is evaluated at runtime. The way you wrote it is like this: Make the expression "Shake $cameraName a random amount each frame, depending on some custom attributes I've set."
What you want it to be is this:Make the expression "Shake " + $cameraName + "a random amount each frame, depending on some custom attributes I've set."
That way it will actually evaluate at runtime what the variable $cameraName is, as opposed to just accepting it wholesale as a camera named "$cameraName".


I am a compositor, but it is a group project, and the person we designated as the compositor doesn't know too much. So we are trying to do as much straight rendering as possible. That way she can't mess up too much

I'd still say it's better to try and teach her how to do things properly. 3d camera shake is probably going to take many revisions to get looking right, and motion blur is a nasty hit to rendertime. I don't know if it's because your team member is very unskilled, or you don't respect your team member very much, but it's better for the group dynamic, and for your team member's growth as an artist, to do it in 2d.

Just my $0.02.

JamSession
03-19-2006, 04:48 PM
OHHH, thank you guys for your help, that makes alot more sense.

My group was furtunate enough to have a member not care about school in general, and does the bare minimum for classes. She just slides by with a C- or even D's. We did sit down and show her how to do some basic compositing like taking all the different passes and putting them together, but she didn't pay attention and started playing world of warcraft on her laptop. If this was a job, she would of been fired multiple times.

So the group decided to render as much as possible leaving her with the least amount of work to do.:D

CGTalk Moderation
03-19-2006, 04: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.