Search code examples
c++importexportmaya

How to extract user-data from a custom material in a .mb with the Maya C++ API?


How can I extract the data the user entered into my custom material's fields when I'm parsing an .mb with the C++ Maya API in my importing app? (I suspect I already have access to an MObject that contains the user's input, but don't know how to extract it)

Here's the situation in greater detail:

  • I defined a custom material with the C++ Maya API (I created an .mll that defines a custom MPxNode, which in turn defines some float and enum fields for the user)
  • in Maya I can "assign new material" to an object with the custom material, and then modify the custom material's datafields and save the .mb
  • in my C++ Maya importer I traverse the DAG and DG and, as expected, note one occurrence of the custom material (so noted by identifying the material MObject as the only one for which the call MObject::hasFn(MFn::kPluginDependNode) returns true)
  • I can extract each of my custom shader's datafields by name using MFnDependencyNode::attribute("datafieldName") -- trying to extract a nonexistent datafield fails as expected

...but these extracted datafields are MObject's, and I don't know how to extract the data the user entered into the custom material instance in Maya.

What's the right approach here?


Solution

  • Here's the missing link I was looking for:

    MFnDependencyNode::findPlug("datafieldName") returns an MPlug, which then provides access to the user-entered data.

    (I was searching for names like "attribute" and "datafield" -- it didn't occur to me to look for anything called a "plug")