Introduction to the Maya C++ API Brent Haley The Ohio State University (bhaley@accad.ohio-state.edu)
Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><u...
Programming for Maya <ul><li>The Book (Complete Maya Programming) </li></ul><ul><li>MEL Scripts </li></ul><ul><ul><li>Can ...
Particles in Maya <ul><li>Maya has a built in particle system </li></ul><ul><li>Can exploit this to build a particle based...
Particle Based Fluid <ul><li>Idea </li></ul><ul><ul><li>Use maya particle dynamics to create the fluid </li></ul></ul><ul>...
Plugin Realization <ul><li>Needs </li></ul><ul><ul><li>Command to create the mud system </li></ul></ul><ul><ul><li>Node(s)...
Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><u...
Create a Visual C++ Project <ul><li>The project creation wizard is not installed </li></ul><ul><li>Make a Win32Project </l...
Open the Project Properties Note: make sure you apply the settings on the next slide to both the debug and release version...
Set the Project Properties <ul><li>C/C++ -> General -> Additional Include Directories: C:Program FilesAliasWavefrontMaya6....
Required Code <ul><li>#include  <maya/MFnPlugin> </li></ul><ul><li>#include  <maya/MObject> </li></ul><ul><li>#include  <m...
Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><u...
Example Command <ul><li>Specification </li></ul><ul><li>class  MudBoxCommand :  public  MPxCommand  </li></ul><ul><li>{ </...
doIt <ul><li>Where the actual work is done </li></ul><ul><li>Changes made to the graph </li></ul><ul><li>Get nodes through...
(De)Register the Command <ul><li>Register commands in the initializePlugin procedure (from the required bit of code) </li>...
Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><u...
Example Node <ul><li>Specification </li></ul><ul><li>class  MudBoxNode :  public  MPxNode </li></ul><ul><li>{ </li></ul><u...
Compute <ul><li>Where the actual work is done </li></ul><ul><li>See examples (mud plugin) </li></ul><ul><li>MStatus MudBox...
(De)Register the Node <ul><li>Register nodes in the initializePlugin procedure </li></ul><ul><li>stat = plugin.registerNod...
Upcoming SlideShare
Loading in...5
×

Intro

272

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
272
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Intro

  1. 1. Introduction to the Maya C++ API Brent Haley The Ohio State University (bhaley@accad.ohio-state.edu)
  2. 2. Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><ul><li>Node Basics </li></ul>
  3. 3. Programming for Maya <ul><li>The Book (Complete Maya Programming) </li></ul><ul><li>MEL Scripts </li></ul><ul><ul><li>Can be really easy to test </li></ul></ul><ul><ul><li>Can see how Maya does its own with echo </li></ul></ul><ul><ul><li>Hard to get complex data structures </li></ul></ul><ul><ul><li>Slow, due to interpretation </li></ul></ul><ul><li>C++ API Plugins </li></ul><ul><ul><li>Very confusing at first (and later), hard to find help / concise examples </li></ul></ul><ul><ul><li>Fast, due to machine language </li></ul></ul>
  4. 4. Particles in Maya <ul><li>Maya has a built in particle system </li></ul><ul><li>Can exploit this to build a particle based fluid dynamics system </li></ul><ul><li>I took a procedural rather than physically based approach </li></ul>
  5. 5. Particle Based Fluid <ul><li>Idea </li></ul><ul><ul><li>Use maya particle dynamics to create the fluid </li></ul></ul><ul><ul><li>Have a voxelized force field, with a different force in each voxel </li></ul></ul><ul><ul><li>Force depends on particles as well as constants </li></ul></ul>
  6. 6. Plugin Realization <ul><li>Needs </li></ul><ul><ul><li>Command to create the mud system </li></ul></ul><ul><ul><li>Node(s) to do the computations </li></ul></ul><ul><ul><li>Visual cues to locate where the field is </li></ul></ul><ul><ul><li>Go FAST (so I used the API + split particle system) </li></ul></ul>
  7. 7. Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><ul><li>Node Basics </li></ul>
  8. 8. Create a Visual C++ Project <ul><li>The project creation wizard is not installed </li></ul><ul><li>Make a Win32Project </li></ul><ul><li>Under application settings, choose dll and empty project </li></ul>
  9. 9. Open the Project Properties Note: make sure you apply the settings on the next slide to both the debug and release versions (all configs should work).
  10. 10. Set the Project Properties <ul><li>C/C++ -> General -> Additional Include Directories: C:Program FilesAliasWavefrontMaya6.0include </li></ul><ul><li>C/C++ -> CommandLine -> Additional Options: /I &quot;C:Program FilesAliasWavefrontMaya6.0include“ </li></ul><ul><li>C/C++ -> Preprocessor -> Preprocessor Definitions: WIN32;NDEBUG;_WINDOWS;NT_PLUGIN </li></ul><ul><li>Linker -> General -> Output File: change the .dll to .mll </li></ul><ul><li>Linker -> Input -> Additional Dependencies: opengl32.lib Foundation.lib OpenMaya.lib OpenMayaUI.lib OpenMayaAnim.lib OpenMayaFX.lib OpenMayaRender.lib </li></ul><ul><li>Linker -> CommandLine -> Additional Options: /LIBPATH:&quot;C:Program FilesAliasWavefrontMaya6.0lib&quot; /export:initializePlugin /export:uninitializePlugin </li></ul>
  11. 11. Required Code <ul><li>#include <maya/MFnPlugin> </li></ul><ul><li>#include <maya/MObject> </li></ul><ul><li>#include <maya/MStatus> </li></ul><ul><li>MStatus initializePlugin(MObject obj) </li></ul><ul><li>{ </li></ul><ul><li>MStatus stat; </li></ul><ul><li>MFnPlugin plugin(obj, &quot;Brent Haley&quot;, &quot;2.2.1&quot;, &quot;5.0.1&quot;); </li></ul><ul><li>return (stat); </li></ul><ul><li>} </li></ul><ul><li>MStatus unintializePlugin(MObject obj) </li></ul><ul><li>{ </li></ul><ul><li>MStatus stat; </li></ul><ul><li>MFnPlugin plugin(obj); </li></ul><ul><li>return (stat); </li></ul><ul><li>} </li></ul><ul><li>Initialize plugin procedure is an entry point that gets called when you load your plugin in Maya </li></ul><ul><li>Uninitialize plugin procedure is an entry point that gets called when you unload your plugin from Maya </li></ul><ul><li>Remember these were specified under the project settings </li></ul><ul><li>Through these entry points we tell Maya what Nodes and Commands our Plugin has </li></ul>
  12. 12. Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><ul><li>Node Basics </li></ul>
  13. 13. Example Command <ul><li>Specification </li></ul><ul><li>class MudBoxCommand : public MPxCommand </li></ul><ul><li>{ </li></ul><ul><li>public : </li></ul><ul><li>//creator function </li></ul><ul><li>static void *creator(); </li></ul><ul><li>//command execution functions </li></ul><ul><li>virtual MStatus doIt( const MArgList &args); </li></ul><ul><li>virtual MStatus redoIt(); </li></ul><ul><li>virtual MStatus undoIt(); </li></ul><ul><li>virtual bool isUndoable() const ; </li></ul><ul><li>private : </li></ul><ul><li>//graph modifier, used to support undo and redo </li></ul><ul><li>MDagModifier dagMod; </li></ul><ul><li>}; </li></ul><ul><li>Implementation (except doIt) </li></ul><ul><li>void *MudBoxCommand::creator() </li></ul><ul><li>{ </li></ul><ul><li>return new MudBoxCommand; </li></ul><ul><li>} </li></ul><ul><li>MStatus MudBoxCommand::redoIt() </li></ul><ul><li>{ </li></ul><ul><li>//commit the work set in doIt </li></ul><ul><li>MStatus stat = dagMod.doIt(); </li></ul><ul><li>return (stat); </li></ul><ul><li>} </li></ul><ul><li>MStatus MudBoxCommand::undoIt() </li></ul><ul><li>{ </li></ul><ul><li>//erase any work set in doIt </li></ul><ul><li>MStatus stat = dagMod.undoIt(); </li></ul><ul><li>return (stat); </li></ul><ul><li>} </li></ul><ul><li>bool MudBoxCommand::isUndoable() const { return ( true );} </li></ul>
  14. 14. doIt <ul><li>Where the actual work is done </li></ul><ul><li>Changes made to the graph </li></ul><ul><li>Get nodes through selection </li></ul><ul><li>Get data through those nodes “plugs” </li></ul><ul><li>Be careful not to setup a cyclic graph </li></ul><ul><li>See examples (mud & joint extractor plugins, note the joint extract is a LOT simpler to script) </li></ul>
  15. 15. (De)Register the Command <ul><li>Register commands in the initializePlugin procedure (from the required bit of code) </li></ul><ul><li>stat = plugin.registerCommand( </li></ul><ul><li>&quot;makeMud&quot;, </li></ul><ul><li>MudBoxCommand::creator); </li></ul><ul><li>if (!stat) MGlobal::displayError(&quot;register MudBoxCommand failed&quot;); </li></ul><ul><li>Deregister commands in the unitializePlugin procedure </li></ul><ul><li>stat = plugin.deregisterCommand(&quot;makeMud&quot;); </li></ul><ul><li>if (!stat) MGlobal::displayError(&quot;deregister MudBoxCommand failed&quot;); </li></ul>
  16. 16. Topics <ul><li>Mud Plugin Introduction </li></ul><ul><li>How to Create a MLL </li></ul><ul><li>Command Basics </li></ul><ul><li>Node Basics </li></ul>
  17. 17. Example Node <ul><li>Specification </li></ul><ul><li>class MudBoxNode : public MPxNode </li></ul><ul><li>{ </li></ul><ul><li>public : </li></ul><ul><li>//identifier </li></ul><ul><li>static MTypeId id; </li></ul><ul><li>//attributes </li></ul><ul><li>static MObject boxCenterX; </li></ul><ul><li>… </li></ul><ul><li>//creator function </li></ul><ul><li>static void *creator(); </li></ul><ul><li>//initializer for the node </li></ul><ul><li>static MStatus initialize(); </li></ul><ul><li>//computational function to do the real work </li></ul><ul><li>virtual MStatus compute ( const MPlug &plug, MDataBlock &data); </li></ul><ul><li>private : </li></ul><ul><li>… </li></ul><ul><li>}; </li></ul><ul><li>Implementation (except for compute) </li></ul><ul><li>void *MudBoxNode::creator() </li></ul><ul><li>{ </li></ul><ul><li>return new MudBoxNode; </li></ul><ul><li>} </li></ul><ul><li>MStatus MudBoxNode::initialize() </li></ul><ul><li>{ </li></ul><ul><li>//create the attributes for spacial subdivision </li></ul><ul><li>MFnNumericAttribute boxAttributes; </li></ul><ul><li>boxCenterX = boxAttributes.create(&quot;boxCenterX&quot;, &quot;bcx&quot;, MFnNumericData::kDouble, 0.0); </li></ul><ul><li>... </li></ul><ul><li>//add the attributes to the node </li></ul><ul><li>addAttribute(boxCenterX); </li></ul><ul><li>... </li></ul><ul><li>//specify attribute relations </li></ul><ul><li>attributeAffects(boxCenterX, boxData); </li></ul><ul><li>... </li></ul><ul><li>//return without error </li></ul><ul><li>return (MS::kSuccess); </li></ul><ul><li>} </li></ul>
  18. 18. Compute <ul><li>Where the actual work is done </li></ul><ul><li>See examples (mud plugin) </li></ul><ul><li>MStatus MudBoxNode::compute ( const MPlug &plug, MDataBlock &data) { </li></ul><ul><li> MStatus stat; </li></ul><ul><li> //determine which output plug needs to be computed </li></ul><ul><li> if (plug == boxData) { </li></ul><ul><li> //get input data handles </li></ul><ul><li> MDataHandle boxCenterXData = data.inputValue(boxCenterX); </li></ul><ul><li> ... </li></ul><ul><li> //turn input handles into data </li></ul><ul><li> double bcx = boxCenterXData.asDouble(); </li></ul><ul><li> ... </li></ul><ul><li> //get output data handles </li></ul><ul><li> MDataHandle outputBoxData = data.outputValue(boxData); </li></ul><ul><li> //turn output handles into data </li></ul><ul><li> <SNIP> </li></ul><ul><li> //set the output data and mark the plug </li></ul><ul><li> outputBoxData.set(ssbDataFn.object()); </li></ul><ul><li> data.setClean(plug);} </li></ul><ul><li> else </li></ul><ul><li> //the plug is for an ancestor, return unknown </li></ul><ul><li> stat = MS::kUnknownParameter; </li></ul><ul><li> return (stat);} </li></ul>
  19. 19. (De)Register the Node <ul><li>Register nodes in the initializePlugin procedure </li></ul><ul><li>stat = plugin.registerNode( </li></ul><ul><li>&quot;MudBoxNode&quot;, </li></ul><ul><li>MudBoxNode::id, </li></ul><ul><li>&MudBoxNode::creator, </li></ul><ul><li>&MudBoxNode::initialize, </li></ul><ul><li>MPxNode::kDependNode </li></ul><ul><li>); </li></ul><ul><li>if (!stat) MGlobal::displayError(&quot;register MudBoxNode failed&quot;); </li></ul><ul><li>Deregister nodes in the uninitializePlugin procedure </li></ul><ul><li>stat = plugin.deregisterNode(MudBoxNode::id); </li></ul><ul><li>if (!stat) MGlobal::displayError(&quot;deregister MudBoxNode failed&quot;); </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×