QUOTE(cfree68f @ Jan 28 2007, 04:35 PM)
Yeah part of my interest in this post was to see if we could drum up some out of the box thinking on what expressions might be able to do.
I many cases, expressions act like the opposite of relationships and so it is not that hard to work out the right place to use it.
Relationships are attached to the driving bone, channel or pose slider and can control one or many other A:M objects.
Expressions are stored in the destination channel (for example the X transform parameter of a model) and can be driven by any number of other channels in its calculations.
So basically if you want one thing to control many things, relationships are the obvious choice. When you want many things to control one thing, expressions are best. When one thing is controlling one thing, you can use either but you would probably use a single constraint if possible.
There are also some types of calculations that are much easier to implement in equations rather then relationships such as motion driven by time.
Where can you use Expressions? Basically anywhere - in models, in actions or in choreography.
Say for example in a chor, I wanted a model to always be in the geometric center of a group of 9 other models. I could do it by creating 9 translate constraints from my center model to each of the 9 objects the group.
Or I could use a single expression in each of the X, Y and Z channels of the center object which would seem a much simpler and neater solution.
Now if you want to try relationships out, you will soon realise that you have absolutely no hope of writing anything more then a very simple equaition directly in an expression edit box.
You build the equation in a text editor and paste it in. And Don't try the complex eqution right from the start.
So for example I want My model "M10" to always stay at the geometric center of models M1, M2, M3, M4, M5, M6,M7, M8 and M9.
I first write out a equation in the text editor in an understandible form:
X translate of M10 = average of X translate of M1, M2, M3, M4, M5, M6,M7, M8 and M9 ie
M10.X= ( M1.X + M2.X + M3.X + M4.X + M5.X + M6.X + M7.X + M8.X + M9.X ) / 9.0
So I have added together the X translate for the 9 models and I have divided by 9.0 to get the average X translate. That is hopefully simple enough to understand. You will see in a moment why I haven't gone straight to the final expression.
Now M1.X of course isn't a proper path to the X translate channel of object M1. I will use the Expression edit box to capture the correct path to the channel and I find it is:
Don't think that experienced users somehow know what these paths will be. You just let A:M tell you what the path is.
OK. Now is the time to stop thinking. Just take the equation above and paste the proper X translate paths in. Don't try and understand it - just do it.
If you do, you get this for the expression on the right of the = sign in the equation:
(..|..|..|..|M1.Transform.Translate.X + ..|..|..|..|M2.Transform.Translate.X + ..|..|..|..|M3.Transform.Translate.X + ..|..|..|..|M4.Transform.Translate.X + ..|..|..|..|M5.Transform.Translate.X + ..|..|..|..|M6.Transform.Translate.X + ..|..|..|..|M7.Transform.Translate.X + ..|..|..|..|M8.Transform.Translate.X + ..|..|..|..|M9.Transform.Translate.X)/9.0
Just paste that into M10's X translate Expression edit box.
Now using the text editor, replace all the ".X"'s with ".Y"s and paste into M10's Y Translate Expression, and likewise for Z.
So for anyone who has looked at expressions written by others, the initial reaction is "I have no hope of understanding this - no way can I do this". Once you start building equations yourself, you will generate equally long and incomprehensible expressions, but generating them is really not that hard.
Two tips that really help are (1) most values used by expressions are floating point numbers with a range from 0.to 1.0 (So Red=255, Transparency = 100%, or time in timeline = 1 second are all represented in expressions by the value 1.0) and (2) parentheses are your friend - if you are not sure about the order inwhich calculations will be done, stick the brackets in to force the order.