View Full Version : Help making sure the result of an expression never go over a certain value.
11-13-2012, 12:23 PM
beware I'm a total noob at MEL so be patient if these are the worst looking expressions you ever seen ;)
I'm creating a set of control for a head, they basically are connected via expression to blendshapes.
Now let's take the lips for example: I have 2 separated controller for the Left and the Right part plus I created a third controller that will take care of both sides at the same time.
A brief explanation:
Left = LipCtrl_L
Right = LipCtrl_R
Both = LipCtrl_B
Now this is the expression I used:
BS.Right_Smile_geo = clamp (0, 0.1, LipCtrl_R.translateY) * 10 + clamp ( 0, 1, LipsCtrl_B.translateY * 10);
BS.Right_Frown_geo = clamp (0, 0.1,- LipCtrl_R.translateY) * 10 + clamp ( 0, 1, - LipsCtrl_B.translateY * 10);
BS.Left_Smile_geo = clamp (0, 0.1, LipCtrl_L.translateY) * 10 + clamp ( 0, 1, LipsCtrl_B.translateY * 10);
BS.Left_Frown_geo = clamp (0, 0.1,- LipCtrl_L.translateY) * 10 + clamp ( 0, 1, - LipsCtrl_B.translateY * 10);
BS.Right_Narrow_geo = clamp (0, 0.05, - LipCtrl_R.translateZ)*20 + clamp ( 0, 1, -LipsCtrl_B.translateZ * 10);
BS.Left_Narrow_geo = clamp (0, 0.05, LipCtrl_L.translateZ)*20 + clamp ( 0, 1, -LipsCtrl_B.translateZ * 10);
What I'm running into is that, obviously, if I have the left controller and the right controller at their max value and then I add the third controller the blendshape basically goes to 2, is there a way to make sure this value never goes over 1?
You may get a few ideas from watching some of HippyDrome's videos...
This does not cover the technical aspects of actually rigging it, but its still worth a look.
To answer your question, with another question... Do you really need the symetrical control? I'd be happy animating without it. If you do want it, you could maybe multiply the L and R results by (1-B) . However, rather than expressions, my prefernce would be to use a node based setup in combination with SDKs.
11-13-2012, 02:40 PM
hey djx thanx a lot for your reply,
to answer your question "Do you really need the symetrical control?"
the main reason that brought me down this path is that some of the blendshapes controlled separately by the left and right controls will be used not only for emotion but for lipsync as well and I thought that maybe during that process someone would like to have a faster way to deal with the shapes instead of having to do everything twice, wich might become tedious whenever you don't really care about assimmetry,
but again I'm not 100% sure it's the right call since I don't have much experience in neither animation nor rigging.
"my prefernce would be to use a node based setup in combination with SDKs."
and that raises another question :) why SDKs instead of expressions?
why don't you just surround each expression with another clamp() function to make sure your result never exceeds 1?
11-13-2012, 06:08 PM
thanx for your suggestion
I thought about doing that but I am not sure on how to write it down...
would it be something like this?
clamp (0, 1, BS.Right_Smile_geo = clamp (0, 0.1, LipCtrl_R.translateY) * 10 + clamp ( 0, 1, LipsCtrl_B.translateY * 10));
this doesn't seem to do the trick though since that blendshape keeps on adding to itself...
Well you have syntax issues in there as well, so first I'd recommend reading the documentation on MEL and expression syntax so you get that down.
As for the solution, I'd put the original expression into a variable and then use that in a new clamp:
$rightSmile = clamp (0, 0.1, LipCtrl_R.translateY) * 10 + clamp ( 0, 1, LipsCtrl_B.translateY * 10);
BS.Right_Smile_geo = clamp(0,1, $rightSmile);
Something like that.
11-13-2012, 07:38 PM
Thanx a lot for your time Nyro, I will take your advice and read the documentation.
why SDKs instead of expressions? Easier to specify the relationship between the driver and the driven shapes. With expressions you would use things like clamp, linstep, smoothstep, etc to construct a mapping between the driver attribute and the shapes it is controlling, but that is fairly limiting unless your math skills reign supreme. I find it much easier to visualize and modify that mapping by looking at and manipulating the sdk curve in the graph editor. And for complex setups where that one driver attribute triggers different shapes fading in and out at different values, you can see the curves all at once and know pretty much how they will be interacting. This would not be so obvious with expressions.
If you combine sdks with utility nodes you end up with a pretty robust rig. You could argue that it is harder to hook up than writing expressions, but it can be scripted, so in a way I'm putting the effort into the creation script and debugging that, instead of into the expressions.
11-14-2012, 11:18 AM
I never messed up with SDKs curves before but I will definetely look into it,
particularly the part where you say: " [...] you can see the curves all at once and know pretty much how they will be interacting" sounds promising.
Again thank you very much for your help.
11-14-2012, 11:18 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.