Introduction to the Maya C++ API Brent Haley The Ohio State University

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

CSE 105 Structured Programming Language (C)
Configuration management
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
The Web Warrior Guide to Web Design Technologies
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Trees. 2 Definition of a tree A tree is like a binary tree, except that a node may have any number of children Depending on the needs of the program,
Trees. Definition of a tree A tree is like a binary tree, except that a node may have any number of children –Depending on the needs of the program, the.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
JavaScript & jQuery the missing manual Chapter 11
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Introduction to Maya Dependency Graph Programming
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Lecture 02: Intro to SDL Topics: Downloading / Installing SDL Linking (in general and for SDL) SDL basics References:
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Introduction to the Maya C++ API Brent Haley The Ohio State University
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
111 Introduction to OGRE3D Programming: Main Loop.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Introduction to Maya Programming Shuen-Huei Guan CML, CSIE, National Taiwan University 2003/10/7.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Open project in Microsoft Visual Studio → build program in “Release” mode.
Multiple File Compilation and linking By Bhumik Sapara.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
CS777 Project 1 Developing Maya Plug-ins for motion related projects Kyungsuk David Lee.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
Topic 2: Hardware and Software
Lesson #6 Modular Programming and Functions.
Lesson #6 Modular Programming and Functions.
Trees.
Introduction to Events
CMPE 152: Compiler Design ANTLR 4 and C++
What is Bash Shell Scripting?
Lesson #6 Modular Programming and Functions.
MEL Interface with Maya.
Trees.
Lesson #6 Modular Programming and Functions.
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
The Role of Command Line Compiler (csc.exe)
SPL – PS1 Introduction to C++.
Plug-In Architecture Pattern
Presentation transcript:

Introduction to the Maya C++ API Brent Haley The Ohio State University

Programming for Maya The Book (Complete Maya Programming) Maya Help (Developer Resources, Commands, Nodes, API Classes) MEL Scripts –Can be really easy to test –Can see how Maya does its own with echo –Hard to get complex data structures –Slower, due to interpretation C++ API Plug-ins –Very confusing at first, hard to find help / concise examples –Faster, due to machine language

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples

Simple Scene in Maya 3D View, Hypergraph, and Outliner Using built in functionality Mocap driven animation

Nodes, Plugs, and Attributes Note: I’m zooming in on LilyGeometry to get the 2 nd image

Turning Character into Smoke Create a built in fluid container Have the vertices on Lily’s surface generate density values Requires a way to link Lily’s output geometry to the fluid container’s density values in the hypergraph Note: Lily’s input geometry is driven by her original mesh + skeletal rig and smooth skin binding

Using a Plug-in (1) Add new nodes and commands to Maya Requires one to load the plug-in

Using a Plug-in (2) Select the required components Run the command

Tweak the SmokeNode1 Attributes

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples

Create a Visual C++ Project The project creation wizard may not be installed (or doesn’t work correctly) Make a Win32Project Under application settings, choose dll and empty project

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).

Set the Project Properties C/C++ -> General -> Additional Include Directories: C:\Program Files\Alias\Maya8.0\include C/C++ -> Preprocessor -> Preprocessor Definitions: WIN32;NDEBUG;_WINDOWS;NT_PLUGIN Linker -> General -> Output File: change the.dll to.mll Linker-> General -> Additional Libarary: C:\Program Files\Alias\Maya8.0\lib Linker -> Input -> Additional Dependencies: opengl32.lib Foundation.lib OpenMaya.lib OpenMayaUI.lib OpenMayaAnim.lib OpenMayaFX.lib OpenMayaRender.lib Linker -> CommandLine -> Additional Options: /export:initializePlugin /export:uninitializePlugin

Required Code (main.cpp) #include MStatus initializePlugin(MObject obj) { MStatus stat; MFnPlugin plugin(obj, "Brent Haley", “1.0", “8.0"); return(stat); } MStatus unintializePlugin(MObject obj) { MStatus stat; MFnPlugin plugin(obj); return(stat); } Initialize plugin procedure is an entry point that gets called when you load your plugin in Maya Uninitialize plugin procedure is an entry point that gets called when you unload your plugin from Maya Remember these were specified under the project settings Through these entry points we tell Maya what Nodes and Commands our Plugin has

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples

Example Command Specification class GeomToDensityCmd: public MPxCommand { public: //creator function static void *creator(); //command execution functions virtual MStatus doIt(const MArgList &args); virtual MStatus redoIt(); virtual MStatus undoIt(); virtual bool isUndoable() const; private: //graph modifier, used to support undo and redo MDagModifier dagMod; }; Implementation (except doIt) void *GeomToDensityCmd::creator() { return new GeomToDensityCm; } MStatus GeomToDensityCmd::redoIt() { //commit the work set in doIt MStatus stat = dagMod.doIt(); return(stat); } MStatus GeomToDensityCmd::undoIt() { //erase any work set in doIt MStatus stat = dagMod.undoIt(); return(stat); } bool GeomToDensityCmd::isUndoable() const {return(true);}

doIt Where the actual work is done Changes made to the graph Get nodes through selection Get data through those nodes “plugs” Be careful not to setup a cyclic graph See day 2 VC++ examples

(De)Register the Command Register commands in the initializePlugin procedure (from the required bit of code) stat = plugin.registerCommand( “geom2smoke", GeomToDensityCmd::creator); if (!stat) MGlobal::displayError("register MudBoxCommand failed"); Deregister commands in the unitializePlugin procedure stat = plugin.deregisterCommand(“geom2smoke"); if (!stat) MGlobal::displayError("deregister MudBoxCommand failed");

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples

Example Node Specification class SmokeNode : public MPxNode { public: //identifier static MTypeId id; //attributes static MObject filterSize; … //creator function static void *creator(); //initializer for the node static MStatus initialize(); //computational function to do the real work virtual MStatus compute (const MPlug &plug, MDataBlock &data); private: … }; Implementation (no compute) void *SmokeNode::creator() {return new SmokeNode;} MStatus SmokeNode::initialize() { //create the attributes MFnNumericAttribute fsAttribute; filterSize = fsAttribute.create(“filterSize", “fs", MFnNumericData::kInt, 0);... //add the attributes to the node addAttribute(filterSize);... //specify attribute relations attributeAffects(filterSize,is2D);... //return without error return(MS::kSuccess); }

Compute Where the actual work is done MStatus SmokeNode::compute (const MPlug &plug, MDataBlock &data) { MStatus stat; //determine which output plug needs to be computed if (plug == is2D) { //get input data handles MDataHandle filterSizeData = data.inputValue(filterSize);... //turn input handles into data int fs = filterSizeData.asInt();... //get output data handles MDataHandle cfdData = data.outputValue(is2D); //turn output handles into data //set the output data and mark the plug cfdData.set(false); data.setClean(plug); } else //the plug is for an ancestor, return unknown stat = MS::kUnknownParameter; return(stat);}

(De)Register the Node Register nodes in the initializePlugin procedure stat = plugin.registerNode( “SmokeNode", SmokeNode::id, SmokeNode::creator, SmokeNode::initialize ); if (!stat) MGlobal::displayError("register SmokeNode failed"); Deregister nodes in the uninitializePlugin procedure stat = plugin.deregisterNode(SmokeNode::id); if (!stat) MGlobal::displayError("deregister SmokeNode failed");

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples

Warnings (1) Node Ids need to be unique Bad: Good: In NodeA’s implementation: MTypeId NodeA::id(0x43215); In NodeB’s implementation: MTypeId NodeB::id(0x43215); In NodeA’s implementation: MTypeId NodeA::id(0x43215); In NodeB’s implementation: MTypeId NodeB::id(0x43216);

Warnings (2) Attribute affects shouldn’t be multi-level Create several nodes instead of trying to accomplish everything in a single node Bad: Good: In NodeA’s initialize() procedure: attributeAffects(X,Y); attributeAffects(Y,Z); In NodeA’s initialize() procedure: attributeAffects(X,Y); In NodeB’s initialize() procedure: attributeAffects(S,T); Where Y’s output is plugged into S’s input

Warnings (3) Don’t create cyclic structures in the hypergraph (can result in infinite loops)

Warnings (4) Per-frame node evaluation will occur in chunks if you use the rendering farm –Don’t rely on old values from the previous frame in your code since they may not exist –Alternatively (if you really need to), Explicitly step the time back for each frame Particles can be cached Dynamics can be forced to run from the start time to the current time before rendering each frame

Topics Day 1 –Plug-in Introduction –How to Create a MLL –Command Basics –Node Basics –Warnings Day 2 –VC++ Examples