Maya and Node Types

In Maya, both intrinsic and user-defined Maya Objects are registered and recognized by their type identifier or type id. The basis of the type id system is a tag which is used at run-time to determine how to create and destroy Maya Objects, and how they are to be input/output from/to files. These tag-based identifiers are implemented by the class MTypeId.

Darkvador
Before going into more details, we need to come back briefly on that statement “type identifier or type id”. A type identifier is a string and actually the node name, like for example ‘polySphere’ for the polygon sphere definition. The name is used for several things:

  • be able to create the node via a MEL command. I.e.   createNode polySphere;
  • save/read nodes in/from Maya ASCII file
  • give the default naming for a newly created node of that type

A type id is a numerical 32 bits integer which is used by Maya internal to identify a node type at runtime. The Id is used for few other things:

  • register/unregister the node into the Maya kernel
  • save/read nodes in/from Maya binary file

Being a 32 bits integer, it is unlikely we have nodes with the same IDs in a file unless you do not register the ID for your nodes. This is why you will need to register a block before shipping a file with one custom node of yours inside.

Fingerprint
The numeric ID ranges have been divided like this. Ids in range

  • 0 – 0x0007FFFF has been reserved for plug-ins that will forever be internal to your site. But while we reserved those for your internal usage, I would recommend having your own range just in case you share a file and a plug-in with a customer, vendor or contractor many years later.
  • 0x00080000 – 0x000FFFFF has been reserved for Maya devkit samples. If you customize one of these plug-in examples, you should change the id to avoid future conflicts.

To get a
new range assigned to you, just go on http://www.autodesk.com/developmaya
and scroll to the Tool section at the bottom of the page. You’ll find a link
there to self register your ID range.

Now how to use these IDs is where the documentation isn’t always very clear. So let review the 2 options we have to build a new MTypeId. There is two MTypeId constructors.

  1. MTypeId  (unsigned int  id) 
  2. and MTypeId  (unsigned int  prefix, unsigned int  id)

What is important to understand is that the second constructor does something like this:

fId = id & 0x000000ff;
fId |= (prefix & 0xffffff) << 8;

All it does is to clamp only the ‘low’ 24b off the first argument vs. high order, and bitwise left shift by 8 that parameter. In case you’ve been assigned a range like: (I indeed chose something complicated for the sample)

0x00072DC0 – 0x00072E3F (128 Ids)

It means that you cannot use the second constructor as is since the low order part is equal C0. So you need to be careful on how to use that constructor.

To start with the first constructor, you can either do this

MTypeId tp0 (0x00072DC0);
MTypeId tp1 (0x00072DC1);
MTypeId tp2 (0x00072DC2);
...
MTypeId tpx (0x00072E3F)

But you cannot use the 2nd constructor as is. I.e.

MTypeId wrongtp0 (0x00072D, 0);
MTypeId wrongtp1 (0x00072D, 1);
MTypeId wrongtpx (0x00072D, 128); // or 0x80

because you would define Ids like this, and your range really starts a 0xC0 only:

wrongtp0 =0x00072D00
wrongtp1 =0x00072D01
wrongtpx  =0x00072D80

but you can do this

MTypeId tp0 (0x00072D, 0xC0);
MTypeId tp1 (0x00072D, 0xC1);
...
MTypeId tpx (0x00072D, 0xFF); // not your last Id, but the last one valid for the 0x00072D prefix
MTypeId tpy (0x00072E, 0x00);
...
MTypeId lasttp (0x00072E, 0x3F); // this is the 128i of your range

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading