[Closed] Clamping values
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 );
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
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.
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
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.
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!