Ok, but where is it?
If you take a look to the Maya API documentation you will find a lot of things about 64b support, but the only classes specific to 64b will be:
- the MUint64Array which is an array of MUint64 data type,
- the MFnUInt64ArrayData class which allows the creation and manipulation of the MUint64Array objects for use in the dependency graph when the MDataHandle::type() method returns kUInt64Array.
The MFnUInt64ArrayData / MUint64Array / MUint64 classes are present in the API to support Subdivision surface (I.e. MFnSubd / MFnSubdNames / MFnUint64SingleIndexedComponent / MItSubdEdge / MItSubdFace / MItSubdVertex)
Now there are some other classes in the devkit like the Mint64 class, but you would not find it documented anywhere since there isn't any direct use of it anywhere in Maya or the Maya DG :(
There is currently no support of single signed / unsigned 64b integer attribute in Maya, but fortunately for us, Maya is versatile in a way that it can handle any data type (simple or complex). Anyone can eventually expose a custom attribute type. The example provided along this post demonstrate how to do this. But before we go into details there is one important thing to know before using 64b attributes in Maya. While the Maya API (C++ or Python) can work easily with 64b integer. MEL and the Python commands will not! This is because MEL is not 64b capable. The MEL engine is a 32b engine only, so you would not be able to query a 64b integer attribute value and store it into a MEL variable for example.
Example: assuming myInt64 is a 64b integer attribute
$val64 = 0xFFFFFFFF64; // that will fail since MEL cast it to 0x7FFFFFFF which is a signed 32b integer setAttr sphere1.myInt64 $val64; // already wrong on the line above setAttr sphere1.myInt64 0xFFFFFFFF64; // that will work, see below why getAttr sphere1.myInt64; // that will fail with an error, MEL will never return a value
getAttr fails because the MEL interpreter cannot handle 64b integer since MEL is a 32b engine. But then why setAttr is working fine to assign a 64b integer? Simply because the value is passed as a string and evaluated in by the C++ API vs MEL interpreter. However we can't read it back :(
Python setAttr/getAttr commands will behave exactly the same since the Python commands are wrapper of the MEL equivalent commands. So even if the Python interpreter can handle 64b integer variable, when it goes to the MEL interpreter, you'll get the same results. At the time of this post, only the API (C++ and Python) can work with 64b integer attribute.
An 64b attribute implementation
First we need to define and create the class which Maya will use to handle our 64b integer data. For this we will create and register a class in Maya using the MPxData base class.
class MInt64Data : public MPxData {}; MFnPlugin.registerData (MInt64Data::typeName, MInt64Data::id, MInt64Data::creator, MPxData::kData)
This is really the only thing you need to do to add 64b attribute support in Maya. The complete implementation for the MInt64Data can be found in the sample here (Int64AttributeData sample). From there, when the plug-in is loaded in Maya, Maya can handle static, dynamic, and extension attributes with 64b integer data type.
The sample also expose and exports a MFn class to handle the attribute data type from an API standpoint. The class is class MFnInt64Data derived from MFnPluginData.
class DLLIMPEXP MFnInt64Data : public MFnPluginData {};
The Int64AttributeDataNodes sample is there to supply a node which can connect to our 64b attributes and convert data back and force to string, so it they can be used to read/write 64b integer from MEL indirectly as string. It also use an unsigned int64 data type vs signed unlike the previous example.
The Int64AttributeDataWC is another sample which tries to solve the MEL limitation another way by splitting a 64b attribute data in low and high word numbers into a MEL array.
Comments
You can follow this conversation by subscribing to the comment feed for this post.