Playing with Maya thru MEL/ API Min Gyu Choi Kwangwoon University - - PowerPoint PPT Presentation

playing with maya thru mel api
SMART_READER_LITE
LIVE PREVIEW

Playing with Maya thru MEL/ API Min Gyu Choi Kwangwoon University - - PowerPoint PPT Presentation

Playing with Maya thru MEL/ API Min Gyu Choi Kwangwoon University Alias Maya Alias|Wavefront Maya is one of the greatest and most complex computer programs ever made. Alias Maya Alias Maya Maya has many features as default. Maya


slide-1
SLIDE 1

Playing with Maya thru MEL/ API

Min Gyu Choi Kwangwoon University

slide-2
SLIDE 2

Alias Maya

Alias|Wavefront Maya is one of the greatest and most complex computer programs ever made.

slide-3
SLIDE 3

Alias Maya

slide-4
SLIDE 4

Alias Maya

Maya has many features as default.

Maya Complete Maya Unlimited

slide-5
SLIDE 5

Alias Maya

However, Maya cannot do everything!

  • You can “bend” Maya in your direction.

Develop your own features.

  • Automate and simplify tasks

Advanced macros and your own GUI

  • Add new features that are not incorporated

New file formats, object types and behaviors New dynamics and animation components

  • e.g., Maya Fur, Live, Cloth, Hair, and Fluid Effects
slide-6
SLIDE 6

Developing Maya Plug-I ns

Types of Maya plug-ins

  • MEL (Maya Embedded Language) commands
  • Nodes/commands, manipulators, contexts, locators

Maya API (Application Programmer Interface)

  • Gives almost unlimited access to the internal Maya interface

You can also use MEL through Maya API.

slide-7
SLIDE 7

Maya API

  • OpenMaya

OpenMaya for defining nodes/commands

  • Also for assembling them into a plug-in
  • OpenMayaUI

OpenMayaUI for creating new user interface elements

  • Manipulators, contexts, and locators
  • OpenMayaAnim

OpenMayaAnim for animation

  • Including deformers and inverse kinematics
  • OpenMayaFX

OpenMayaFX for dynamics

  • OpenMayaRender

OpenMayaRender for performing rendering functions

slide-8
SLIDE 8

Getting Started

To create a new plug-in

1. Start Visual Studio .NET 2. Invoke File→New→Project and select Visual C++ Projects 3. Select MayaPlugInWizard 4. Enter the solution name and location 5. Fill in the information

Plug-in setup, Plug-in type, Included libraries

By the way, what to develop?

Refer to Appedix I

slide-9
SLIDE 9

What to Develop?

No More “Hello World!”

slide-10
SLIDE 10

Elastodynamic Deformation

Elastodynamic equation for FEM

F u K u C u M = + + ) ( & & &

Linearization

F u K u C u M = + + & & & u: displacement

3n x 3n matrix, 3n x 1 vector

Time-consuming!!! Not real-time!!!

slide-11
SLIDE 11

Elastodynamic equation for FEM

Modal Analysis

[Pentland & Williams ’89]

Q q K q C q M

q q q

= + + & & & ) ( ) ( t t q Φ u =

Modal basis

i i i

Φ K Φ M λ =

3n x 3n matrix, 3n x 1 vector

  • G. eigenvalue problem

F u K u C u M = + + & & & F u K u C u M = + + ) ( & & &

There can be linearization artifacts!!!

Linearization

Diagonal matrices

Time-consuming!!! Not real-time!!!

i i i i i i i

Q q k q c q m = + + & & &

Real-time performance!!!

slide-12
SLIDE 12

Modal analysis in local coordinate frames

Modal Warping

[I EEE TVCG 2005]

Q q K q C q M

q q q

= + + & & & ) ( ) ( t t

L

q Φ u =

Modal basis

i i i

Φ K Φ M λ = dt t t

k

t k

Φ = ) ( ) ( q R u &

  • G. eigenvalue problem

F u K u C u M = + + ) ( & & &

Real-time performance without linearization artifacts!!!

Linearization

F R u K u C u M

T

= + +

L L L

& & &

Modal warping

slide-13
SLIDE 13

Modal Warping

slide-14
SLIDE 14

The First Plug-I n

How to obtain volume meshes for FEM?

  • NETGEN converts polygonal meshes into volume meshes.

How to obtain polygonal meshes?

slide-15
SLIDE 15
slide-16
SLIDE 16

Click

slide-17
SLIDE 17
slide-18
SLIDE 18

Click and then choose “Shelf Editor…” MEL command, ExportMesh What is this?

slide-19
SLIDE 19

MEL Script Associated with a Shelf I tem

ExportMesh defined in the File “ExportMesh.mel”

global proc string export(string $filename, string $filetype ) { meshExport $filename; return $filename; } global proc ExportMesh() { fileBrowserDialog -m 1 -fc "export" -an "Export"; } // We will develop this command using Maya API.

slide-20
SLIDE 20

MEL Script Path

How to locate the script file “ExportMesh.mel”?

  • Maya searches MAYA_SCRIPT_PATH first.
slide-21
SLIDE 21

Command for Polygonal Mesh Export

slide-22
SLIDE 22

Command for Polygonal Mesh Export

meshExport.h

slide-23
SLIDE 23

Command for Polygonal Mesh Export

meshExport.cpp DagPath?

slide-24
SLIDE 24

Command for Polygonal Mesh Export

meshExport.cpp

// For all vertices in the polygon // For all polygons in the mesh

Press F7 to compile and Link!

slide-25
SLIDE 25

Commands for Polygonal Mesh Export

How to load plug-ins (DLLs or MLLs)

MAYA_PLUG_IN_PATH

slide-26
SLIDE 26

The Second Plug-I n

Integrate the elastodynamic equation through time Displace the vertices

F u K u C u M = + + ) ( & & & u : displacement

Excitation (external motion)

slide-27
SLIDE 27

Solid Deformer

The dependency graph is the heart of Maya.

  • DG nodes are used for almost everything in Maya.
  • e.g., model creation, deformation, animation, simulation, …
  • utTime

input worldMatrix[0] matrix[0]

  • utput

currentFrame

  • utputGeometry[0]

inMesh

dimeCluster1.outputGeometry[0] → dinosaurShape.inMesh root.worldMatrix[0] → dimeCluster1.matrix[0] time1.outTime → dimeCluster1.CurrentFrame

(DAG node) Connections Plugs (Motion)

slide-28
SLIDE 28

Registration of the Deformer Node

slide-29
SLIDE 29

Deformer Node

class DSolidDeformer : public MPxDeformerNode { public: static MTypeId id; MObject currentFramePlug; MObject matrixPlug; Mobject rigidityPlug; // ... public: DSolidDeformer(); ~DSolidDeformer(); static void* creator(); static MStatus initialize(); virtual MStatus deform(MDataBlock&, MItGeometry&, const MMatrix&, unsigned); // ... };

Plugs dSolidDeformer.h

slide-30
SLIDE 30

Deformer Node

This method is called once after the plug-in is loaded.

  • Define the inputs and outputs of the node

MStatus DSolidDeformer::initialize() { currentFramePlug = nAttr.create(“currentFrame”,“cf”, MFnNumericData::kLong); nAttr.setDefault(0); nAttr.setHidden(true); MStatus status = addAttribute(currentFramePlug); if (!status){ status.perror(“addAttr()”); return status; } // ... attributeAffects(currentFramePlug, outputGeom); // ... }

slide-31
SLIDE 31

Deformer Node

MStatus DSolidDeformer::deform(MDataBlock& block, MItGeometry&, const MMatrix&, unsigned) { MStatus status; MDataHandle inputData; inputData = block.inputValue(currentFramePlug, &status); int currentFrame = inputData.asLong(); // ... // computes displacedVertices ... MArrayDataHandle outputData;

  • utputData = block.outputArrayValue(outputGeom, &status);

MDataHandle outMesh = outputData.outputValue(&status); MFnMesh mesh(outMesh.asMesh(), &status); mesh.setPoints(displacedVertices, Mspace::kWord); return status; }

Output Input

slide-32
SLIDE 32

Creating Deformer Nodes

Press F7 to compile and link

  • You have to do many things …

Load the plug-in Create a deformer node, and then connect the plugs

deformer –type dimeCluster; connect time1.outTime dimeCluster1.currentFrame; connect root.worldMatrix[0] dimeCluster1.matrix[0];

  • This can be automated by MEL and shelf items!
slide-33
SLIDE 33

How to change simulation constants?

slide-34
SLIDE 34

Customizing Attribute Editor

AEdimeClusterTemplate.mel should be located in MAYA_SCRIPT_PATH. AEdimeClusterTemplate.mel

slide-35
SLIDE 35

Additional DAG Nodes for Visualization

To visualize useful information

  • We need to develop additional DAG nodes.

With local axes at the mesh nodes

slide-36
SLIDE 36

Additional DAG Nodes for Visualization

Derived node of MPxSurfaceShape

  • This node gets connection to the deformer node though

backward traversal of the connected plug.

  • (MPxSurfaceShapeUI supports OpenGL for H/W rendering)

drawingParamter

slide-37
SLIDE 37

Additional DG Nodes for Constraints

To specify the manipulation constraints

  • We need to develop additional dependency nodes.

Position-constrained Orientation-constrained Position/Orientation

slide-38
SLIDE 38

Derived node of MPxNode

  • Simple attributes
  • Simple connections

Additional DG Nodes for Constraints

worldMatrix[0] matrix

  • utput

const[0]

slide-39
SLIDE 39

Additional DG Nodes for Constraints

slide-40
SLIDE 40

Additional DG Nodes for Constraints

slide-41
SLIDE 41

Thin-Shelled Deformable Characters

Degenerate cases: more difficult problems

  • Thin shell: 2 dimensional solids, i.e. surfaces

The plug-in is similar to the solid deformer.

slide-42
SLIDE 42

Free-Floating Deformable Characters

Modal warping rigid body simulation

  • Impulse-based collisions and multiple contacts [Baraff ’92, ’94]
slide-43
SLIDE 43

Free-Floating Deformable Characters

  • bstacle[3]
  • bstacle[2]
  • bstacle[1]
  • bstalce[0]

worldMatrix[0] worldMatrix[0] worldMatrix[0] worldMatrix[0]

Obstacles

slide-44
SLIDE 44

Free-Floating Deformable Characters

Modal warping rigid body simulation

  • Impulse-based collisions and multiple contacts [Baraff ’92, ’94]
slide-45
SLIDE 45

Motion Planning

[ACM TOG 2003] MPxSurfaceShape for hardware rendering

  • It can be used for visualization though image composition.
slide-46
SLIDE 46

I mage Composition

Obtain images with depth values Composite images based on depth values

slide-47
SLIDE 47

I mage Composition

slide-48
SLIDE 48

Motion Planning

slide-49
SLIDE 49

Dynamic Strand

Maya can also be used for fast prototyping.

  • By developing a command that adjusts only transform nodes

Movie obtained by playblast

slide-50
SLIDE 50

Dynamic Strand

Maya can also be used for fast prototyping.

  • If successful, develop relatively sophisticated nodes.

Movie obtained by playblast

slide-51
SLIDE 51

Hair Simulation

[SCA 2005] Dynamic strand for hair simulation

  • The image was obtained using Renderman.

Produced by Byungwon Choe

slide-52
SLIDE 52

Summary

Playing with Maya through MEL/API

  • Nodes/Commands

Refer to “Maya Developer’s Manual”

  • C:\Program Files\Alias\Maya6.0\PDF\Reference\API.pdf
  • Developer resources in Maya Help (F1)

For more video clips, type Min Gyu Choi in Google http://cg.kw.ac.kr mgchoi@kw.ac.kr

slide-53
SLIDE 53

Appendix I

slide-54
SLIDE 54
slide-55
SLIDE 55

What if there was not such a wizard?

slide-56
SLIDE 56
slide-57
SLIDE 57
slide-58
SLIDE 58

You can achieve ModalWarping.mll after compiling/linking.

slide-59
SLIDE 59
slide-60
SLIDE 60
slide-61
SLIDE 61

Maya Plugin Wizard

How to install the wizard for Visual Studio .NET?

  • Follow the instructions in

~\Maya6.0\devkit\pluginwizard\MayaWizardReadme.txt NOTE At this time, the Maya install process will not copy the wizard files into the appropriate .NET directories. This process is manual.

  • Unzip a zip file into your .NET directory

~\Maya6.0\devkit\pluginwizard\MayaPluginWizard2.0.zip

slide-62
SLIDE 62

Maya Plugin Wizard

How to install the wizard for Visual Studio .NET?

  • Unzip the MayaPluginWizard2.0.zip file
  • Copy the following files to the "C:\Program Files\Microsoft

Visual Studio .NET 2003\Vc7\vcprojects" directory:

MayaPlugInWizard.vsdir MayaPlugInWizard.vsz

  • Copy the "MayaPluginWizard" directory to "C:\Program

Files\Microsoft Visual Studio .NET 2003\Vc7\VCWizards"

Back to Getting Started

slide-63
SLIDE 63

Appendix I I I

slide-64
SLIDE 64

Directed Acyclic Graph in Maya

Transform nodes Shape nodes (MFnTransform) (e.g., MFnMesh) (MFnDagNode) dinosaur|root|dinosaur

A kind of scene graph

slide-65
SLIDE 65

nVIDIA Cg Plug-In

Dependency Graph Plug-I ns

Twelve parent classes for dependency graph plug-ins

  • MPxNode
  • MPxLocatorNode
  • MPxIkSolverNode
  • MPxDeformerNode
  • MPxFieldNode
  • MPxEmitterNode
  • MPxSpringNode
  • MPxManipContainer
  • MPxSurfaceShape
  • MPxObjectSet
  • MPxTransform
  • MPxHwShaderNode

You can subclass new nodes from these!