PDA

View Full Version : Expressions. . . .


Peace455
09-29-2002, 03:39 AM
Hello my fellow animators.


I have a question I kidna know then answer to but can't put into words if I was asked to write out the defenition, but here it is. . .


What is expressions in Maya? I know it a type of scripting. I saw the rigging movie that is in the character rigging catagory and I was blown away, and realized in aspiring to be a character rigger, I'll need to know live and breath expressions for effient moving characters.

I was wondering if anyone could explain what espression is, and where I could possibly start to learn how to use it.

Thanks sopo very much.

Peace455

MosaFacku
09-29-2002, 05:26 AM
expressions for an animator aren't always such a treat man. i find them downright frustrating. here's a post that a friend of mine made for one of his rigs, and he's got some comments about his expressions from people that do this for a living at some pretty cool places

http://www.cgtalk.com/showthread.php?s=&threadid=21445


later.
:buttrock:

MCronin
09-29-2002, 05:37 AM
An expression in Maya or any 3D application is a collection of numerics, variables, and symbols that explain a relationship mathematicly. Here is a psuedo example...

Y= the scale in Y of a cube
F= the current frame

Y = F*0.5

The above expression means that the Y scale value of the cube will be set to half of the current frame number. So, when you run the animation, without setting any keyframes at all, the cube will constantly get taller as the animation plays.

Frame 1, the height of the cube will be 0.5, at frame 2 the height becomes 1, at frame 3 the height is 1.5, etc.

With more complex expressions, you can do more complicated things, like tieing the rotation of a shoulder joint to the value of a blendshape slider for a bicep muscle that's used as an influence object under the skin of your character. Then, when the shoulder is rotated, the bicep flexes automaticly, and deforms the character's skin.

You can use expresions to do all sorts of stuff, from automatic animation, to physics, to shaders, to modeling. 3D graphics is all mathematics.

If you want to be good with expressions, you just need to understand that everything you do in 3D can be explained mathematicly. Next, you need to learn the mathematics behind 3D. It's a bit more involved than simple algebra, you'll need to know a thing or two about Geometry, Trig, and Linear Algebra. Sounds like a lot, but it really isn't. Thankfully you only need to really know a handful of things from each discipline.

Books I recommend: "Geometry for Dummies". Basic Geometry in plain english that you will need to understand to grasp trigonometric functions like sine and cosine and tangents. Geometry for Dummies has a chapter or two that explain these trig functions clearly. After that, there's "3D Math Primer for Graphics and Game Development". You may not be imterested in the C++ aspect of the book, but it covers the application of expressions in computer generated 3D. It'll cover most of what you need to know in writing expressions for Maya. Vectors, Scalars, Coordinates, Matricies, Transformations, Euler and Quaternions, it's all covered in this book.

Lastly, I never really looked in the Maya help, but Houdini has an expressions cookbook. It's a very handy reference no matter what software you use. It shows you all sorts of common expressions for generating effects mathematicly. Waves of all types (sine square, saw, ripple, spirals, etc) deformations (shear, squash and stretch, tpers, etc) it's all covered, and it's applicable to any 3D software that lets you use expressions. I know Maya has an expressions help file, I'm just not certain how thorough it is. You can get the Houdini expression cookbook with Houdini Apprentice. It's chapter 9 of the tutorial guide.

If you aren't good with math it sounds like a lot to learn but it's a necessary evil. It's not that bad, any average high school student should understand this stuff, and it'll greatly improve your understanding and posibilities with Maya or any 3D software for that matter.

Crode
09-29-2002, 06:55 AM
so far... ive only found expressions usefull for particles. things like colour changing based on speed per particle, etc

ambient-whisper
09-29-2002, 07:36 AM
you could use sine waves to create ripples on a grid
you could use a sine square expression with a variating frequency to control a light flicker.
hell you could add a clamped sine expression to a characters legs for creating easy walk cycles.

( ive seen one houdini guy create an entire walk cycle all based on expressions and no keyframes. and it didnt look bad.

-wT-
09-29-2002, 02:30 PM
Well the Maya help doesn't really give you any examples as is, but explains clearly how things work, and has explanations of every MEL command.

Btw, I just recently did a small two lined expression - can't remember what it was for anymore - and I noticed that I had to play the animation for atleast one frame before the expression was "turned on", is this normal and is there a workaround?

artifish
09-29-2002, 03:07 PM
the maya doc's on expressions are quite good (imo), as they have lot's of examples and nice diagrams showing you, what's going on. As MCronin already said, a basic knowledge of math and programming is required, but you'll learn the math is your friend, fast ;)
especially when it come's to simulating/antimating mechanics they are in fact often the way to go (try keyframing a wheel rolling on the floor and you'll see what i mean)

i've got some more or less simple examples of expression on my site (tutorial section), you could check them out to get an idea what expression can do for you. > http://www.kolve.com

here is a test i recently made:

http://home.arcor.de/ckolve/spiderWalkTest.avi
(about 700k, bad quaility compression, but you'll get the idea)

the spider is completly animated through expressions - not a single keyframe was used here. you can change the motion path, the terrain it is walking on, the walking style of the spider, the speed etc. and it will still move correctly. you won't get that kind of flexibility with any other animation technique.

another book i would recommend is "computer animation and techniques" by rick parent to get an understanding of the math involved.
this book looks also interesting: MEL Scripting for Maya Animators
http://groups.google.com/groups?selm=040820020402172377%25mark_DELETEMEwilkins%40yahoo.com&output=gplain
got to check it out myself when it comes out


ambient-whisper:you won't happen to have some more informations on the houdini-walk-cycle stuff? maybe an url? was it a human walk cycle?

cheers, carsten

ambient-whisper
09-29-2002, 07:12 PM
Originally posted by artifish

ambient-whisper:you won't happen to have some more informations on the houdini-walk-cycle stuff? maybe an url? was it a human walk cycle?

cheers, carsten

unfortumately no. this was about 2-3 years ago using houdini 4.0.
and yes. it was a human character. i didnt really pay much attention to it back then but the guy that did it said it was all expressions.

artifish
09-29-2002, 08:24 PM
-wt-: i have not experienced this behaviour in expression execution. they are evaluated right after creation and i don't have to play the animation at all. maybe you could find the expression again and we'll find out, what caused this behaviour?

ambient-whisper: ok, nevermind - just did a quick search on this and there are quite a lot of graphics papers dealing with the subject of procedurally animating human walk. so in case i want to dig deeper in this topic, there is some reference material out there.

cheers, carsten

-wT-
09-29-2002, 10:32 PM
Ooh now I remember, I did an expression which made an object stick to another objects vertex.
I can't remember how it was, but I think it was just three lines, each telling the objectA's vertex to have it's position assigned to the objectB. Veryvery simple expression.

I gotta try it out tomorrow, and see if I can get it not to evaluate again, but now I'll go to bed :)

Peace455
10-01-2002, 02:10 AM
I would like to that all of you for explaining what expressions are, I understand know, and fortunately enjoyed math in my high school (until I got a teacher who lacks the necessary skills to teach us), but other than that I find math enjoyable (as long as I know what I'm doing:D )

I originaly posted this topic after seeing those rigging movies, and how expressions made that rigg as amazing as it was. It inspired me to learn expressions.

I'm going to look in the Maya help and get started with it right away, and see how far I can go with it.

Thanks again.

Peace455:buttrock:

bigfatMELon
10-01-2002, 04:51 PM
My 2.333 cents:

You might rig your entire life and never need of an expression. In fact, it is a far better practice to look for ways to achieve your rigging goes without them. Many of the commonly used rig expressions can be replicated with constraints of texture utility nodes, which makes for faster execution and guaranteed update when the rig is manipulated wihtout having to change frames.

Having said that, expressions can sometimes be handy. though I wouldn't for a minute suggest that should "live and breath them." Learning expressions = learning MEL. And since learning MEL can generally save you enourmous amounts of rigging effort, I think that this is where you should focus your efforts in addition to studying anatomy.

Lastly, MEL and expressions built with them are for more commonly less about math than they are about logic. Having good logic and puzzle solving skills is key. Strong math skills are an added bonus, but I think it's more important to have an artistic (preferrably animation) background. After all, if you intend to be making rigs for animators it helps a cubic assload to have an intimate understanding of how they work.

-jl

-wT-
10-01-2002, 05:23 PM
Ok, I re-created my über-complicated (;)) expression, and it doesn't evaluate immediately after I move the second object.

What I did, was that I first created a sphere and a cube. I moved the pivot of the cube to one of it's verticles, and freezed it's transformations (First moved it back to the center). Then I just put in this expression:

float $temp1[] = `xform -q -ws -t pSphere1.vtx[281]`;
pCube1.translateX = $temp1[0];
pCube1.translateY = $temp1[0];
pCube1.translateZ = $temp1[0];

It works after I move the timeslider, but not before that. I dunno if this was the best method to do that - propably not - and dunno if it's even supposed to get immediately evaluated... but here is it anyways.

jschleifer
10-01-2002, 09:00 PM
The problem with this expression is that there's nothing triggering it to evaluate. Expressions need an attribute which changes to force an evaluation.. otherwise they just wait for time to change.

In this case, it looks like you're moving the pSphere1.. so maybe you can force an evaluation by querying something on the sphere? Try this:

float $foo = pSphere1.boundingBoxMinX;
float $temp1[] = `xform -q -ws -t pSphere1.vtx[20]`;
pCube1.translateX = $temp1[0];
pCube1.translateY = $temp1[1];
pCube1.translateZ = $temp1[2];

see? in this case you're forcing the expression to evaluate by querying the boundingBox of the sphere.

whee!

(also, notice that the tx, ty, and tz work correctly now.. you had them only queyring the x location)

-jason

-wT-
10-01-2002, 09:29 PM
Hmmm... I'm not sure if I understand, aren't I already querying the position of the vertex number XXX with the xform?
Isn't the position of the vertex changing then?
How is the boundingbox query different than the xform query?

Oh and yeah, I had those $temp1[X] correct, but as all of 'em were in their own places (You know how the expression editor works...), so I just copied the first two lines, and pasted the two, and apparently forgot to change the $temp's ;)

Edit: Oh wait... hmmm... is this related to the ``'s? Meaning that those are only queried once per time apparently (Or something), so I need to have something constantly changing, because it is assigned with only the "="?
... or something :) (Hard to explain, english isn't my main language afterall, so I've learned maths and such in finnish, but programming in english... so you go and try to explain something more deep here! :p)

jschleifer
10-01-2002, 10:00 PM
Basically, expressions are just "nodes" within maya. For maya to evaluate any node, it needs to have an incoming connection change, and then the node knows to evaluate.

for example, if you have two spheres conneced in an expression:

nurbsSphere1.tx = nurbsSphere2.tx;

whenever nurbsSphere2.tx changes, maya goes "oh! I gotta change nurbsSphere1.tx now!" so the expression evaluates.

However, if you move bobHead.tx, the expression isn't querying whether or not bobHead.tx is moving.. so it doesn't evaluate.

The way the expression node knows what's invovled in the expression is that each time you have an object.attribute in the expresison, it actually makes a direct connection to that object.attribute.

Make an expression which looks like the one above and then delete nurbsSphere2.

Then look at the expression. Notice how it now looks something like:

nurbsSphere1.tx =.I[0];

the .I[0] is an incoming connection.. which is now broken, because that object doesn't exist anymore. re-create the two spheres and make the following expression instead:

nurbsSphere1.tx = `getAttr nurbsSphere2.tx`;

notice this expression doesn't evaluate until you change time.. and if you delete nurbsSphere2 and look at the expression again, it looks exactly the same. This is because the expression isn't directly connected to nurbsSphere2.tx.. instead it's using a MEL command to query the value. This slows your expression down, AND doesn't provide a direct connection.. thereby causing hte expression not to know whether or not it should evaluate.

Does that make sense?

-jason

artifish
10-02-2002, 01:44 PM
now this threads gets pretty interesting...

from what you've written so far, i suggest there are a lot of unecessary evaluations of an expression? you advice using direct connections as it is faster (which I can understand, compared with the time needed to interprete a mel command) and the expression knows when to evaluate. But when you are writing complex expressions you may want to take many different attributes into account and if all these attributes have a direct connection, every change on one of these attributes will force a reevaluation of the expression. but you may want the expression to evaluate only when a special attribute it is connected to changes. how can you achieve this effect and not use a mel command to retrieve the attribute values needed in your expression? this probably isn't much of an issue in simple scenes, but think of 500 expression controlled characters at once and i am sure this will have an impact...
i wonder whether there is a means to control when my expression (or any other node for that matter) is evaluated, exactly? and speaking of control, i always wondered how the dependcy graph performs in terms of execution time and when which nodes are evaluated (how does my input propagate through the dg?) i already searched the help for this, but the commands which sound like they address these problems (dgPerformance, dgdebug, dgstats, dgfootprint) don't seem to be available right now in maya.

any insights you might have on these problems?

cheers, carsten

bentllama
10-02-2002, 06:38 PM
Originally posted by bigfatMELon
cubic assload

damn, that is a funny retort...

I am laughing my "cubic assloaad" off!

-wT-
10-02-2002, 07:16 PM
Yeah, it's starting to make sense, thanks jschleifer.

So, that small example of mine, can you do it "the-expression-way" then? Atleast I can't think of any other way to split the translation information to three parts other than assigning it to a variable.
Or is this completely ok, as there just isn't a better way to do it? Just have to make a dummy-connection to get it to evaluate?

Gentle Fury
10-11-2002, 05:36 AM
Originally posted by Crode
so far... ive only found expressions usefull for particles. things like colour changing based on speed per particle, etc

expressions can be used for anything and everything.....from character setup, to animation, even for shaders. It is sometimes the only way to achieve a difficult effect efficiently!! I had one project i was working on and i had to animate a field of grass swaying............i used planes with texture and trans. but in order to make it look like grass there were thousands of these planes. It took me a lil while to figure it out, but i came up with a method to get all the planes to sway at random times, on their own. Could NOT have hand animated that! So, sometimes you have to just bust out the help files and write that every tedious expression everyone hates to do!!!!


Happy Rendering!!!!! And Evaluating!!!

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