c++ - How to get Node class instance from MObject in Maya API -
in cpp plugin developing in maya api, register custom mpxtransform node in initializeplugin function:
status=pluginfn.registertransform("mympxtransform", mympxtransformclass::id, &mympxtransformclass::creator, &mympxtransformclass::initialize, &mympxtransformmatrixclass::creator, mympxtransformmatrixclass::id);
and create node programmatically:
mdagmodifier mdagmod; mobject mymobject; mymobject=mdagmod.createnode("mympxtransform",mobject::knullobj,&status);
i can see node created in outliner.
now, how can access custom mympxtransformclass obtained mymobject ?
solution problem:
you have do:
mympxtransformclass* newderived = (mympxtransformclass*)&transformedobj; // 1) // debugging mglobal::displayinfo(newderived->classname());
1) here create pointer of class' type , assign type casted pointer created mobject
. compiler wouldn't allow type-casting mobject
itself, pointer can type-casted class' pointer (mympxtransformclass*
).
we can use pointer access class' methods , on.
p.s. in case of dynamic_cast
, attempting cast mobject
directly won't work because mobject
not polymorphic type (intentionally).
side recommendation:
on side note, wanted add this. this opinion. since don't know trying code, please take recommendation grain of salt.
according core maya's principle,
thou shall never access member functions of node/
mobject
in maya.
once has been created, solely under maya's control. way can (sort of) control using maya's provided function sets (mfn
classes) node type (in case mfntransform
set because node kplugintransformnode
transform node).
in case have class data members might want operate , manipulate programmatically, have make them actual maya attributes node (and thereby expose them maya). then, able them mplugs
, thing.
looking @ code, feel there 2 components majorly aiming produce, node(s) (i.e. custom mpxtransform
); , functor kind of class (i.e. unitclass
) with/to node(s). recommend splitting plugin 2 separate components: node , command. way there clear separation of responsibilities. because, stands right now, loading plugin creates node(s) , operates on them. user might confused might happening. if separated them node , command thing, can used in many different ways user sees fit. command entry point user use plugin.
hope helps!
Comments
Post a Comment