How to add a quaternion attribute on a node?

444 views
Skip to first unread message

yaoys

unread,
Mar 12, 2015, 6:26:47 AM3/12/15
to python_in...@googlegroups.com
Hi all,
I'm going to add an attribute of MQuaternion type on my custom node, but I don't know how to do it? Could anyone give me any clue? Thank you in advance.

Cheers
yao

Rick Silliker

unread,
Mar 12, 2015, 3:31:32 PM3/12/15
to python_in...@googlegroups.com
I could be wrong, but couldn't you just use MFnNumericAttribute and when you create it declare a MFnNumericData.k4Double type?

Joe Weidenbach

unread,
Mar 12, 2015, 4:56:50 PM3/12/15
to python_in...@googlegroups.com
That would be the right way as far as I can see, you can feed the four float values into a new MQuaternion in your node, or output them, depending on the intended result.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9040959f-df23-4549-a940-3de8a664bd73%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

yaoys

unread,
Mar 12, 2015, 10:03:16 PM3/12/15
to python_in...@googlegroups.com


But the problem is how to set the value with MDataHandle?
e.g.
MDataHandle dh = datablock.outputValue(myNode.aQuaternion)
dh.set?(...) # there is not interfaces for set double4 or
quaternion
dh.setClean()

Cheers
yao

Joe Weidenbach

unread,
Mar 13, 2015, 1:31:49 PM3/13/15
to python_in...@googlegroups.com
Ok, I see where you're going, and you're correct, there's no double4 output.

You could make an array of doubles, but my question is why you'd want a Quaternion as an output--to my knowledge, Maya does process rotations internally as a Quaternion, but it converts those to Euler's before it outputs, and I don't know of any plugs that take a Quaternion.

When I've used Quaternions, I normally build my Quaternion internally, use it, and then output as a float3 after converting to a Euler with the appropriate rotation order.

You can do this pretty easily with MEulerRotation--it has asQuaternion(), and MQuaternion has asEulerRotation.

Once you've converted to a MEulerRotation, it's pretty straightforward to put it into a rotation data set.

You basically will need to set up three attributes (rotationX, rotationY, rotationZ) as MFnUnitAttributes with a type of MFnUnitAttribute::kAngle, and then a MFnNumericAttribute (rotation) with the three rotation attributes.  At least that's how I do it--the setup looks something like this in c++ (but Python's very similar), in the initialize() function:

    MFnNumericAttribute nAttr;
    MFnUnitAttribute uAttr;
   
    aRotX = uAttr.create("rotateX", "rx", MFnUnitAttribute::kAngle);
    uAttr.setWritable(false);
    uAttr.setStorable(false);
    aRotY = uAttr.create("rotateY", "ry", MFnUnitAttribute::kAngle);
    uAttr.setWritable(false);
    uAttr.setStorable(false);
    aRotZ = uAttr.create("rotateZ", "rz", MFnUnitAttribute::kAngle);
    uAttr.setWritable(false);
    uAttr.setStorable(false);
    aOutRotation = nAttr.create("outRotation", "or", aRotX, aRotY, aRotZ);
    nAttr.setWritable(false);
    nAttr.setStorable(false);
    nAttr.setArray(true);

Then you just use set3Double to set them.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




This email is free from viruses and malware because avast! Antivirus protection is active.


Reply all
Reply to author
Forward
0 new messages