PDA

View Full Version : Clamping values


Mattrne
05-19-2006, 04:17 PM
I'm attempting to translate a rig I have been given which is in Maya and has some expressions written in Mel. I am in the process of translating these across to Max compatible stuff, but I dont know if Max has a 'clamp' function similar to the one in Mel - does anyone know if there is a similar thing? Basically what I need to do is clamp the movement of a bone - the Maya syntax is as follows;

joint4.translateX = clamp ( -7 , -2 , joint2.translateX - 2 );

PEN
05-19-2006, 04:23 PM
Is this setting it up in Maya so that the joint can't be moved past those values?

If so have a look at the limit controller. I don't have Maya up in frount of me so i can't check what clamp does in MEL

Mattrne
05-19-2006, 04:26 PM
Yep thats exactly what its doing. I'm going to be putting this as an expression controller on a bone, so i think what I'll probably do is rather than putting extra controllers on (which our game engine likely wont handle is just do a set of if statements.

Blue
05-19-2006, 05:25 PM
Here is a simple function that replicates the clamp command in maya

fn clamp minVal maxVal val =
(
if val < minVal then val = minVal
else if val > maxVal then val = maxVal
return val
)
-- test function
clampVal = clamp -6 -4 22
print clampVal

PEN
05-19-2006, 09:24 PM
ah is that all it's doing. If you want a more complex version of the one that Blue posted have a look at my mathLib on my site. It will allow you to clamp a range as well as convert a range.

Mattrne
05-19-2006, 09:26 PM
Thanks guys! I ended up doing a function just like blue had posted, which works perfectly - i have been having bouts a severe brain fade today so it took me a while to think of doing a function to do it myself! Cheers for the help!

CGTalk Moderation
05-19-2006, 09:26 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.