1

I'm coding in Maya API (C++) these days, first thing that I was a little bit confused is that when you define a class in your header file, apparently you only have to make static member variable (attributes), so all the instances share common data. At the same time in Maya for example when I create a instance of a plugin name "Sphere", it creates it and I can change the attributes and everything works fine. But when I create another Sphere object in Maya scene the static attributes have their local values too. Like if I change "Sphere2.radius", it wouldn't update the first instance "Sphere1.radius" at all.

Here is a code that does the same behavior:

class Morpher : public MPxDeformerNode
{
public:
    Morpher();
    virtual ~Morpher();
    static void* creator();
    static MStatus initialize();

    virtual MStatus deform(
        MDataBlock& data,
        MItGeometry& itGeo,
        const MMatrix& localToWorldMatrix,
        unsigned int geomIndex);

    static MTypeId id;
    static MObject aBlendMesh;
    static MObject aRadius;
};

And the initialize function:

MStatus Morpher::initialize(){
    MStatus status;

    MFnNumericAttribute nAttr;
    MFnTypedAttribute tAttr;

    aBlendMesh = tAttr.create("blendMesh", "blendMesh", MFnData::kMesh);
    addAttribute(aBlendMesh);
    attributeAffects(aBlendMesh, outputGeom);

    aRadius = nAttr.create("radius", "radius", MFnNumericData::kFloat);
    nAttr.setKeyable(true);
    nAttr.setMin(0);
    nAttr.setMax(1);
    addAttribute(aRadius);
    attributeAffects(aRadius, outputGeom);

    MGlobal::executeCommand(
        "makePaintable -attrType multiFloat -sm deformer blendMesh weights;");

    return MS::kSuccess;
}

So I wanted to know if you guys have any experience with this API, or am I not understanding the static concept correctly or Maya is handling that part in its own way?

Thanks,

glitchzone
  • 17
  • 4
  • Please, add the tag "maya" to the question. It has more entries and it will be easy to be answered. I'm really interested in knowing the answer, I wonder how Maya manages that. – jgonzac May 27 '15 at 10:04

1 Answers1

0

The answer is very simple (while I agree that both people, and the Maya documentation abuse on terminology when saying 'attribute')

When you create your C++ class, the static variables are the attribute definitions - an attribute definition is not the instantiated values, but only a description of what the attribute is.

Later, when you create an instance of the Maya node, Maya will read the definition, to create an attribute where you can store a value. That attribute is the one you see in Maya, and that host values.

The static variables (i.e. attribute definition) are unique and the same for all instances. The node attribute are owned by Maya node instances and different from other nodes.

I got couple of articles talking about attributes posted there if you need further readings: http://around-the-corner.typepad.com/.services/blog/6a0163057a21c8970d0163057a224d970d/search?filter.q=attributes

cyrille
  • 2,616
  • 1
  • 10
  • 18