PDA

View Full Version : Creating and rotating custom locators


iamsonobody
08-16-2009, 10:40 AM
Hi there Maya gurus.


I'm trying to write a Maya plugin using the c++ api. To make it short, It will track features such as markers from a video or a web cam. For each such marker that are tracked the plugin will create and control a locator in Maya. The plugin is to be used while doing e.g. facial animations by connecting joints or blend shapes to the locators. Now the tracking part is already done and are working just fine, but I'm totaly inexperienced in the black art of Maya plugin programing.




So I have two initial impediments.



How do I add my custom locator(s) to the DAG (or is it DG) programaticly. Is the best way to have my custom locator use the MDagModifier::createNode or am I on the wrong track?
Once the locator are created, how do I get hold of it's transformation matrix or similar so that it I can translate/rotate it in code (based upon the result from the tracking part of the plugin) ?



Any help would be much appreciated,

Thanks

/R

Robert Bateman
08-17-2009, 10:16 AM
For each such marker that are tracked the plugin will create and control a locator in Maya.

I'm afraid that won't happen (ish). Your locators may provide a visual reference, but it won't do anything more than that. All transforms are handled by it's parent transform, and not the locator node itself (which is to be fair, a fairly pointless entity).





How do I add my custom locator(s) to the DAG (or is it DG) programaticly. Is the best way to have my custom locator use the MDagModifier::createNode or am I on the wrong track?
If the data has come via an import command (i.e. you've derived from MPxFileTranslator), then just use MFnDagNode::create. If it's come from a crusty mel command (MPxCommand) then use MDagModifier::createNode() as part of the undo/redo implementation.


Once the locator are created, how do I get hold of it's transformation matrix or similar so that it I can translate/rotate it in code (based upon the result from the tracking part of the plugin) ?


Depends how you created it. Ideally you'll create the transform node first, and pass it as the parent parameter to the create method for the locator shape node. It's then pretty trivial to use the MFnTransform function set on the parent transform to set the TRS data.

If you haven't explicitly created a transform node for the locator, and have just created a locator node directly. Maya will automagically create the parent transform for you (and the MObject returned from the create method will be the transform node, and not the locator). Grab that node and use it in the MFnTransform set.


Whilst that will set the transform of the locator, it won't set the anim data on that node. For that you'll need to create the animation curves and attach them to the relevent translate/rotate plugs on the transform nodes. To do that, either create the animation curves directly (using MFnAnimCurve) and connect them manually. Or, just set the time and the current transform and call setKey (or whatever the mel command is) to autogenerate the anim curves and key frames. You'll get less control over the tangent with the latter method, but that may be enough for what you need....

CGTalk Moderation
08-17-2009, 10:16 AM
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.