PDA

View Full Version : API: Creating Custom Locators


JoshM
04-02-2009, 11:52 PM
Hi Guys,
I'm writing a deformer using the Maya C++ API and everything for the deformer is essentially working. For this deformer I have my own custom locator node (derived from MPxLocatorNode) to display falloff for the deformer. The problem that I am having is in the accessoryNodeSetup(MDagModifier &dagMod) function of the MPxDeformer class. I create my custom locator using the dagMod.createNode() within the node setup function and the node is created properly. I know that when creating an object such as a locator that Maya will automatically create a parent transform for the locator and return the MObject from the createNode function. However, for the life of me I can't get the locator shape beneath this transform so I can access the attributes that I created for the locator. Here's a code snippet:

MStatus myDeformNode::accessoryNodeSetup(MDagModifier &dagMod){
MStatus stat;

//create the locator for the deformer
MObject locatorObj = dagMod.createNode("myDeformNodeHandle", MObject::kNullObject, &stat);
if(!stat) return stat;

MFnDagNode locatorFn(locatorObj);

//find the matrix of the transform
MObject attrMat = locatorFn.attribute("matrix");

//connect the matrix to the deformerMatrix attribute
stat = dagMod.connect(locatorObj, attrMat, thisMObject(), deformerTransformation);
if(!stat) return stat;

//no matter what I do after this point I can't access the locator shape node
//even using the function locatorFn.name() returns an empty string
//yet some how it is able to access the 'matrix' attribute of the transform properly???

return MS::kSuccess;
}

So I'm just curious on how I should go about retrieving the locator shapes MFnDagNode.

Thanks in advance,
Josh

Andimation
04-03-2009, 12:06 AM
Have you tried using MDagPath.extendToShape(transform);

As you have the transform and the locator is a shape of that.

JoshM
04-03-2009, 01:26 AM
Thanks for the quick reply. Yeah, tried that. The problem is that MFnDagNode locatorFn function set provides an empty MDagPath from the locatorFn.getPath(someDagPath) or someDagPath = locatorFn.dagPath(). Even locatorFn.childCount() returns 0 or locatorFn.name() returns an empty string. I was fighting with this all day and nothing I tried seemed to work. The fact that it finds the 'matrix' attribute and makes the connection blows my mind being that I can't even get the name of the object from the function set.

Josh

Robert Bateman
04-03-2009, 01:13 PM
You can't modify the node until you've created it. You probably want to call doIt() on the dag modifier. If that's not do-able in this context, use evalDeferred or the post constructor.

JoshM
04-03-2009, 05:22 PM
Thanks for the reply Robert. Yeah, I just needed to call dagMod.doIt() to actually create the node and now everything is returning the proper data.

As a side note, the examples on your website have been really helpful for learning the Maya API. Thanks for having those available.

Josh

CGTalk Moderation
04-03-2009, 05:22 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.