Introduction to Maya Dependency Graph Programming

Slides:



Advertisements
Similar presentations
PROVENANCE FOR THE CLOUD (USENIX CONFERENCE ON FILE AND STORAGE TECHNOLOGIES(FAST `10)) Kiran-Kumar Muniswamy-Reddy, Peter Macko, and Margo Seltzer Harvard.
Advertisements

Exceptions, Templates, And The Standard Template Library (STL) Chapter 16.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
INTRODUCTION COMPUTATIONAL MODELS. 2 What is Computer Science Sciences deal with building and studying models of real world objects /systems. What is.
File Management Systems
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Run time vs. Compile time
C++ fundamentals.
ACM/JETT Workshop - August 4-5, 2005 UML Modeling using MagicDraw UML for Java Programmers.
Zach Miller Condor Project Computer Sciences Department University of Wisconsin-Madison Flexible Data Placement Mechanisms in Condor.
UNIT-V The MVC architecture and Struts Framework.
IT 210 The Internet & World Wide Web introduction.
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Workflow Management Chris A. Mattmann OODT Component Working Group.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Tutorial 1 Getting Started with Adobe Dreamweaver CS3
Beyond the Visualization Pipeline Werner Benger 1, Marcel Ritter, Georg Ritter, Wolfram Schoor 1 Scientific Visualization Group Center for Computation.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Introduction to the Maya C++ API Brent Haley The Ohio State University
The Java Programming Language
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Cohesion and Coupling CS 4311
1 Extend is a simulation tool to create models quickly, with all the blocks you need and without even having to type an equation. You can use a series.
Software Testing Yonsei University 2 nd Semester, 2014 Woo-Cheol Kim.
Learners Support Publications Classes and Objects.
CS 193G Lecture 7: Parallel Patterns II. Overview Segmented Scan Sort Mapreduce Kernel Fusion.
Advanced ETL: Embedding Integration Services Ashvini Sharma Development Lead DAT411 Microsoft Corporation Sergei Ivanov Technical Lead DAT411 Microsoft.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Use Case Diagram The purpose is to communicate the system’s functionality and behaviour to the customer or end user. Mainly used for capturing user requirements.
Netprog: Corba Object Services1 CORBA 2.0 Object Services Ref: The Essential Distributed Objects Survival Guide: Orfali, Harky & Edwards.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to Maya Programming Shuen-Huei Guan CML, CSIE, National Taiwan University 2003/10/7.
1 EndNote X2 Your Bibliographic Management Tool 29 September 2009 Humanities and Social Sciences Resource Teams.
Introduction to the Maya C++ API Brent Haley The Ohio State University
INTRODUCTION GORT is a virtual 3D modeling environment for computer programmers. Its main area of focus is to aid in the education of programmers learning.
Database Management Systems (DBMS)
Using Objects 1 of 22 Computer Programming Object Classes.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Overview of Previous Lesson(s) Over View 3 Program.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
CS777 Project 1 Developing Maya Plug-ins for motion related projects Kyungsuk David Lee.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Plug-In Architecture Pattern. Problem The functionality of a system needs to be extended after the software is shipped The set of possible post-shipment.
Building Preservation Environments with Data Grid Technology Reagan W. Moore Presenter: Praveen Namburi.
CIS682 Maya Internal Structure Overview. CIS682 Programming Interfaces MEL - Maya Embedded Language –Scripting language –Interpreted –Fast prototyping,
Testing i. explain the importance of system testing and installation planning;
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Game Architecture Rabin is a good overview of everything to do with Games A lot of these slides come from the 1st edition CS 4455.
In-situ Visualization using VisIt
CompSci 230 Software Construction
Programming Interface Overview
GENERAL VIEW OF KRATOS MULTIPHYSICS
Classes and Objects.
Analysis models and design models
Data Structures & Algorithms
A Semantic Peer-to-Peer Overlay for Web Services Discovery
Plug-In Architecture Pattern
Presentation transcript:

Introduction to Maya Dependency Graph Programming Naiqi Weng Developer Consultant, Autodesk Developer Network (ADN)

Biography Naiqi Weng -- Autodesk Developer Network Education Bachelor of Computer Science Master of Computer Science Working experience Supporting software: Maya API, MotionBuilder SDK and 3dsMax SDK Naiqi.weng@autodesk.com

Dependency Graph Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Agenda What is Dependency Graph (DG)? Concepts/Elements of DG Nodes Custom plug-in DG node with Maya API DG’s push-pull mechanism Correct coding with DG Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Maya Hypergraph Menu: “Window”– “Hypergraph:Connections” Nodes Attributes Connections

What is the Dependency Graph? Control system of Maya Patented technology: US Patent #5,808,625 US Patent #5,929,864 A collection of nodes that transmit data through connected attributes A.x B A C B.y

Dependency Graph Everything in Maya 3D space maps to DG Nodes Anything you do in the UI will affect DG File Texture Phong Shader Anim Curve Shading Group poly Time Curve deformer Revolve Transform Surface poly

Dependency Graph © 2009 WET, Artificial Mind and Movement (now Behaviour Interactive) © 2009 Bethesda Softworks.  Image courtesy of Behaviour Interactive

Dependency Graph New Type Custom Node

What does a node do? Node Know its own attributes input attributes output attributes Node Know its own attributes Store data efficiently in “datablocks” Accept input data, compute, generate output data Connect with other nodes through connections

Different elements of a Node Maya Node Attributes DataBlock DataHandle Plugs

“Smiley” Node Attributes Describe data that belongs to nodes of a given type Attributes are shared among nodes of the same type and all derived node types “Smiley” Node Attributes Node A Float “rotation” Float “diameter” Int32 “numEyes” Node B

Attributes Define the interface of the node type including Names Data Type Basic: numeric (float, int32 etc…), string, matrix, etc.. Complex: mesh, nurbsSurface, generic, etc… Custom data Structure Properties readable, writable, storable, keyable, etc… pSphereShape1.colors colors[0] colors[1] colors[2] colors[n] ….. colorR colorG colorB colorA pSphereShape1.face face[0] face[1] face[2] face[n] ….. pSphere1.translate translateX translateY translateZ Simple, compound, array, compound array

API Classes for Attributes Base Class: MFnAttribute Takes care of all the common aspect of an attribute on node readable/writable, connectable, storable, keyable Most Common Used Classes MFnNumericAttribute MFnCompoundAttribute MFnTypedAttribute MFnMatrixAttribute MFnGenericAttribute

Different elements of a Node Maya Node Attributes DataBlock DataHandle Plugs

Actual instance of a node Plugs Pointer to an attribute on a specific node (ie. a specific instance of an attribute) setAttr myNode1.myAttr 5; setAttr myNode2.myAttr 10; Node type definition Actual instance of a node myNode myNode1 myNode2 myAttr myPlug1(myNode1, myAttr) myPlug2(myNode2, myAttr)

Plugs Plugs can be used to: Does not store attribute data query / set a value create / remove /query a connection Does not store attribute data API class: MPlug MPlug::MPlug (const MObject &node, const MObject &attribute) MObject MPlug::attribute ( MStatus *  ReturnStatus)  MObject MPlug::node ( MStatus *  ReturnStatus)  MStatus MPlug::getValue ( double &  val, MDGContext &  ctx ) MStatus MPlug::setValue ( double  val  ) 

Different elements of a Node Maya Node Attributes DataBlock DataHandle Plugs

Datablock Node stores data for every attribute Datablock Attribute

Datablocks Datablock is the actual storage for the input and output data of a node For every non-array attribute, datablock stores: Data Dirty/clean status Data handles are lightweight pointers into the data in the datablock

API Classes for datablock MDatablock Only valid during compute() Pointers to data block should not be retained after compute() MStatus MPxNode::compute(const MPlug& plug, MDataBlock& dataBlock) MDataHandle MDataBlock::inputValue(const MObject& attribute, MStatus *  ReturnStatus) MDataHandle MDataBlock::outputValue ( const MObject & attribute, MStatus *  ReturnStatus) MDataHandle a smart pointer for information contained in data block double & MDataHandle::asDouble (  )  void MDataHandle::set( double  val  ) 

MPxNode Maya Node Attributes DataBlock DataHandle Plugs MFnAttribute MDataBlock MDataHandle MPlug

Custom Node Plug-in Implementation Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Custom DG Node in Maya Entirely new operations MPxNode: base class for custom node implementation Extend existing Maya nodes MPxDeformerNode MPxFieldNode MPxEmitterNode MPxSpringNode MPxIkSolverNode MPxHwShaderNode

Custom Node Code Skeleton class myNode : public MPxNode { public: myNode(); virtual ~myNode(); static void* creator(); static MStatus initialize(); virtual MStatus compute( const MPlug& plug, MDataBlock& data ); private: static MTypeId id; static MObject myInputAttr; //input attribute static MObject myOutputAttr; //output attribute static MObject myOutputAttrTwo; //second output attribute };

Custom Node Registration Every node type requires a unique identifier MTypeId myNode::id( 0x80000 ); For plug-ins that you intend to share between sites Will require a globally unique ID issued to you by Autodesk. IDs are allocated in blocks of 64/128/256/512. Contact ADN M&E for unique global IDs. 0 – 0x7ffff (524288 ids) 0x80000 – 0xfffff 0x100fff – 0xffffff Internal Use DevKit Examples Global IDs

Custom Node Registration initializePlugin() and uninitializePlugin() are entry point and exit point of custom plug-in node Maya API Maya initializePlugin uninitializePlugin loadPlugin unloadPlugin

Custom Node Registration To register your node with Maya: To deregister your node MStatus initializePlugin(MObject obj) { MFnPlugin plugin(obj, “Autodesk”, “1.0”, “any”); MStatus status = plugin.registerNode(“myNode”, myNode::id, myNode::creator, myNode::initialize); return status; } MStatus uninitializePlugin(MObject obj) { MFnPlugin plugin(obj); MStatus status = plugin.deregisterNode( myNode::id ); return status; }

Custom Node Code Skeleton MPxNode::creator() The creator method is called to return a new instance of the node In the Maya UI MEL: createNode myNode; void* myNode::creator() { return new myNode; }

Custom Node Code Skeleton MPxNode::initialize() Override this method to define the attribute interface for your node. create attributes set the attribute’s properties add the attribute to the node Inherit attributes if necessary define attribute relationships Node input attributes output attributes input 1 output1 ? input 2 output2

Attribute Dependency Attributes can affect other attributes MEL command: affects sphere -n sphere; affects tx sphere; MPxNode::attributeAffects() Once created on a node, an “attributeAffects” relationship can be setup to denote a dependency radius D volume setAttr D.radius 5 attributeAffects(radius,volume)

Custom Node Code Skeleton MStatus myNode::initialize() { MFnNumericAttribute nAttr; myInputAttr = nAttr.create(“myInput”, “mi”, MFnNumericData::kFloat, 1.0); nAttr.setStorable(true); myOutputAttr = nAttr.create(“myOutput”, “mo”, MFnNumericData::kFloat, 1.0); myOutputAttrTwo = nAttr.create(“myOutputTwo”, “motwo”, MFnNumericData::kFloat, 1.0); addAttribute(myInputAttr); addAttribute(myOutputAttr); addAttribute(myOutputAttrTwo); attributeAffects(myInputAttr, myOutputAttr); return MS::kSuccess; }

Custom Node Code Skeleton MPxNode::compute() called when the node is asked to evaluate an output MStatus myNode::compute(const MPlug& plug, MDataBlock& dataBlock) { if (plug = = myOutputAttr ) //your compute algorithm for output1 } if (plug = = myOutputAttrTwo) //your compute algorithm for output2 return MStatus::kUnknownParameter getAttr myNode1.myOutput; myOutput myNode myInput myOutputTwo

Examples Devkit Plug-in Examples: C:\Program Files\Autodesk\Maya2011\devkit\plug-ins The Maya API Documentation contains a wealth of information on all aspects of the API. API Docs

How does Dependency Graph work? Control system for Maya Glue that holds together disparate operations and lets them work together seamlessly DG is not a usual dataflow system…. data Literature Experts Database List Producer Holding Format Transfer Web site

How does Dependency Graph Work? Two step Push-Pull mechanism: Dirty Propagation Evaluation Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Dirty Propagation Maya DG caches values Uses dirty system to denote elements that require updating: Attributes Connections MEL Commands: dgdirty isDirty Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Data Flow Example Key = clean connection, = dirty connection B A C D E

The Dirty Process Initiated by value changes B A C D setAttr D.r 5; E

The Dirty Process Dirty message propagates forward B A C D E

The Dirty Process No evaluation has been requested. Data remains dirty. B A C D E

The Dirty Process Now an input on A changes B A C setAttr A.aIn 6 D E

The Dirty Process Dirty propagates out all outgoing connections B A C

The Dirty Process B and D propagate dirty to affected attributes C will not receive dirty message Connection to C is already dirty Helps performance B A C D E

The Evaluation Process Lazy Evaluation: On demand Evaluation is trigged when values are requested: Viewport refresh Attribute editor Channel box Rendering getAttr command Etc… Evaluation is minimal Only requested values are computed Non-requested values are left dirty

The Evaluation Process Example: getAttr C.output B A C getAttr c.output D E

The Evaluation Process C computes: requests input value from connection B A C ? D E

The Evaluation Process D computes. D requests input value from connection B A C ? D E

The Evaluation Process A computes requested output B A C D E

The Evaluation Process Value copied forward to D’s input B A C D E

The Evaluation Process D computes requested result. D sets value in output. B A C D E

The Evaluation Process Value is copied forward to C B A C D E

The Evaluation Process C computes requested output. B remains dirty. B A C D E

The Evaluation Process Only requested outputs are computed, unless node’s compute method does more than requested Node input output1 output2

Correct Coding with DG Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Correct Coding with DG Common misuse: Black Box Rule put command-type tasks into a custom node implementation execute commands to change the status of current DG get or set values on other nodes Black Box Rule Node input attributes output attributes

Black Box Rule Black-box operation of node is what makes it all work.

A Closer Look at MPxNode::compute() You can not control when compute() is getting called, Maya control when it gets called Compute() is called in Evaluation phase Inside compute(): avoid sending dirty messages Don’t execute commands Don’t get or set values on other nodes Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

A Closer Look at MPxNode::compute() Inside compute(): avoid sending dirty messages Get/set data only through datablock using data handles, don’t set data via plugs (i.e. MPlug::setValue) setting data via plug propagates dirty, datahandle does not datahandle set/get methods are more efficient MPxNode::compute() MPlug::getValue() MPlug::setValue() MDataHandle::asXXX() MDataHandle::setXXX()

Learning Resources Maya Developer Center: http://www.autodesk.com/developmaya Questions and Problems: ADN http://www.autodesk.com/adn Maya API White Paper, DevTV, Webcast training Discussion Forum: The AREA http://area.autodesk.com/forum/autodesk-maya/sdk/ Image courtesy of Johan Vikström, Shilo, The Spine, National Film Board of Canada Production ©, Ool Digital, Mikros Image

Q & A

Thank you! Please fill out the survey, let us know what you think