Your SlideShare is downloading. ×
0
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Intro
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Intro

266

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
266
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Introduction to the Maya C++ API Brent Haley The Ohio State University (bhaley@accad.ohio-state.edu)
  • 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. 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. 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. 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. 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. 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. 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. 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. Set the Project Properties <ul><li>C/C++ -&gt; General -&gt; Additional Include Directories: C:Program FilesAliasWavefrontMaya6.0include </li></ul><ul><li>C/C++ -&gt; CommandLine -&gt; Additional Options: /I &amp;quot;C:Program FilesAliasWavefrontMaya6.0include“ </li></ul><ul><li>C/C++ -&gt; Preprocessor -&gt; Preprocessor Definitions: WIN32;NDEBUG;_WINDOWS;NT_PLUGIN </li></ul><ul><li>Linker -&gt; General -&gt; Output File: change the .dll to .mll </li></ul><ul><li>Linker -&gt; Input -&gt; Additional Dependencies: opengl32.lib Foundation.lib OpenMaya.lib OpenMayaUI.lib OpenMayaAnim.lib OpenMayaFX.lib OpenMayaRender.lib </li></ul><ul><li>Linker -&gt; CommandLine -&gt; Additional Options: /LIBPATH:&amp;quot;C:Program FilesAliasWavefrontMaya6.0lib&amp;quot; /export:initializePlugin /export:uninitializePlugin </li></ul>
  • 11. Required Code <ul><li>#include &lt;maya/MFnPlugin&gt; </li></ul><ul><li>#include &lt;maya/MObject&gt; </li></ul><ul><li>#include &lt;maya/MStatus&gt; </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, &amp;quot;Brent Haley&amp;quot;, &amp;quot;2.2.1&amp;quot;, &amp;quot;5.0.1&amp;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. 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. 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 &amp;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. 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 &amp; joint extractor plugins, note the joint extract is a LOT simpler to script) </li></ul>
  • 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>&amp;quot;makeMud&amp;quot;, </li></ul><ul><li>MudBoxCommand::creator); </li></ul><ul><li>if (!stat) MGlobal::displayError(&amp;quot;register MudBoxCommand failed&amp;quot;); </li></ul><ul><li>Deregister commands in the unitializePlugin procedure </li></ul><ul><li>stat = plugin.deregisterCommand(&amp;quot;makeMud&amp;quot;); </li></ul><ul><li>if (!stat) MGlobal::displayError(&amp;quot;deregister MudBoxCommand failed&amp;quot;); </li></ul>
  • 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. 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 &amp;plug, MDataBlock &amp;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(&amp;quot;boxCenterX&amp;quot;, &amp;quot;bcx&amp;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. 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 &amp;plug, MDataBlock &amp;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> &lt;SNIP&gt; </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. (De)Register the Node <ul><li>Register nodes in the initializePlugin procedure </li></ul><ul><li>stat = plugin.registerNode( </li></ul><ul><li>&amp;quot;MudBoxNode&amp;quot;, </li></ul><ul><li>MudBoxNode::id, </li></ul><ul><li>&amp;MudBoxNode::creator, </li></ul><ul><li>&amp;MudBoxNode::initialize, </li></ul><ul><li>MPxNode::kDependNode </li></ul><ul><li>); </li></ul><ul><li>if (!stat) MGlobal::displayError(&amp;quot;register MudBoxNode failed&amp;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(&amp;quot;deregister MudBoxNode failed&amp;quot;); </li></ul>

×