Maya sine function


#1

As we all know, Maya still does not have a built in node for a sine function, or any other kind of trig. The closest it has, as far as I know, is the sine Deformer, or just putting a locator in a rotating transform - both of these methods require the answer to be found physically in the scene.
This CANNOT be the best way to do things, so I’d like your help to find it. Out of these, which will be the most efficient, when hundreds are used in the scene:
-Previous spatial methods
-Writing a simple sine expression
-Coding your own
-Using an animcurve as a lookup table to approximate sine values

As I understand it, the animcurve is the only one which does not actually calculate the value, it just looks it up (assuming the curve itself does not change) - would that be the best way?

Thanks


#2

I don’t know the best way. I’m not against reading the rotation of a transform if it works.

I just wanted to let you know that remapValue nodes look up the value along a range too, rather than using an animCurve. And you can animate or drive the positions and values of the curves.

For example, the attributes in a PyMEL example, where the 0 and 1 indeces are the points of the curve. You can can connect and drive them and get some pretty cool effects.

remapNode = pm.createNode('remapValue')
remapNode.value[0].value_Position
remapNode.value[0].value_FloatValue
remapNode.value[0].value_Interp

remapNode.value[1].value_Position
remapNode.value[1].value_FloatValue
remapNode.value[1].value_Interp

#3

FWIW an expression with a single float input and output is the simplest way – there’s an incremental speed loss compared to a C++ node, but the likelihood that actually affects your seen on a modern machine is very slim.


#4

I would say an expression is probably best choice, without knowing the exact specifics of the setup in question.

If you can deploy custom nodes I would suggest my library:


#5

Also node “eulerToQuat” can be used to calculate a sine result. Angle input to node “eulerToQuat” should be pre-multiplied by 2, then result is the same as sin(Angle).


#6

That’s amazing! It’s exactly what I need, I can’t believe more people don’t know about this. Thanks!


#7

Your welcome! It’s just maths, but yeah finding way to apply it in Maya can be tricky sometimes :slight_smile:
One more thing to note is that to get exact sine of angle using “eulerToQuat” node, better to use no more that one input to “inputRotate”, while keeping other inputs set to 0 (or ℤ*720, where ℤ is any of Intergers).


#8

Also has the handy characteristic of giving both sine and cosine as outputsX and W for a single input angleX.


#9

Amazing hot tip right here, thanks Karolis!


#10

I can’t locate this node in maya 2017… I’m using createNode method but get an unknown node instead.


#11

Make sure to load the “quatNodes” plugin.