power&python&development for&maya€¦ · for&maya jasonparks technical&ar:st...

91
Power Python Development for Maya Jason Parks Technical Ar:st Sony Online Entertainment Sunday, March 6, 2011

Upload: others

Post on 11-May-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Power  Python  Developmentfor  Maya

Jason  Parks

Technical  Ar:st

Sony  Online  Entertainment

Sunday, March 6, 2011

Page 2: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline•Background

•Poll

•Takeaway

•Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

•PyMEL  v.  maya.cmds

•Eclipse  IDE  and  PyDev

•Wing  IDE  as  Debugger

•Conclusion 2

Sunday, March 6, 2011

Page 3: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Background

•SCEA  (Sony  Computer  Entertainment  America)–12  years

•SOE  (Sony  Online  Entertainment)–2  years

•Maya  and  MoKonBuilder

•Rigging  and  Mocap3

Sunday, March 6, 2011

Page 4: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Presenta4ons•2005  Siggraph  :  Alias  MasterClass  “MEL  for  ArKsts”

•2005  GDC  :  Helper  Joints  -­‐  Advanced  DeformaKons  on  RunTime  Characters

•2006  GDC  :  Muscle  Systems  for  Game  ProducKon

•2007  Siggraph  :  Autodesk  MasterClass  “Python  for  MoKonBuilder  ArKsts” 4

Sunday, March 6, 2011

Page 5: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Poll

•Use  Maya

•How  many  script?–MEL?•  sKll?

–Python?•Maya?  PyMEL?

5

Sunday, March 6, 2011

Page 6: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Poll

•Object  Oriented  Programming  (OOP)  experience?

•API/SDK  experience?

6

Sunday, March 6, 2011

Page 7: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Poll

•Use  a  Script  Editor?

–Notepad  ++,  UltraEdit,  MEL  Studio  Pro,  jEdit

OR

•Use  IDE  (programming  environment)

–Eclipse,  Wing,  Visual  Studio7

Sunday, March 6, 2011

Page 8: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Target  Audience

•Maya  scripKng/programming

•Advanced  Scripters

•Ideal  experience–Lots  of  MEL

–Maybe  some  Python  and/or  PyMEL

8

Sunday, March 6, 2011

Page 9: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Takeaway

•Python  rocks–Especially  for  Maya

•Superb  Maya  Development  =–PyMEL

–Eclipse  as  primary  IDE

–Wing  for  debugging  in  RealKme

9

Sunday, March 6, 2011

Page 10: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway–Use  Cases  -­‐  Gene:cs  Tool,  Rig  Build

• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion 10

Sunday, March 6, 2011

Page 11: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

11

Sunday, March 6, 2011

Page 12: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

12

Sunday, March 6, 2011

Page 13: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion13

Sunday, March 6, 2011

Page 14: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

MEL  =  0        PYTHON  =  1

•No  Brainer–MEL  was  fun,  good  start•First  step  

–Commit  some  weeks

–Second  language  is  easier•Python  

14

Sunday, March 6, 2011

Page 15: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

15

Sunday, March 6, 2011

Page 16: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Python  Features

•String  Methods–  Dozens  of  cool  ways  to  manipulate,  slice  strings

–  regex,  regular  expressions

–  Single,  Double,  Triple,  and  Quad  quotes–  Nice  formahng

16

Sunday, March 6, 2011

Page 17: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

string $myList[] = ();for ($i=0;$i<10;$i++){

$myList[$i] = (“item” + $i);}

for i in range(0,10):myList.append(‘item%s’%i)

//MEL

#Python

Python  Features•File  System  Package  is  complete–shuKl,  os,  os.path,  path

• Lists,  DicKonaries

17

Sunday, March 6, 2011

Page 18: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Python  Features

•FuncKons  are  polymorphic–Call  many  ways,  variables  can  change  type

–Arbitrarily  nested  returns

•Plenty  of  xml  and  SQL  libraries

• List  comprehensions–  fun  python  trick

18

Sunday, March 6, 2011

Page 19: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

string $joints[] = {};int $i = 0;for ($sel in `ls -sl`){

if (objectType($sel) == “joint”){

$joints[$i] = $sel;$i = $i + 1;

}}

joints = [j for j in ls(sl=1) if objectType(j) == ‘joint’]

// MEL

# Python

Python  Features

19

Sunday, March 6, 2011

Page 20: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Python  Features• Logging  module  replaces  all  print  and  debug  statements

•Compile  to  .pyc  or  .exe

•Tons  of  resources  and  tutorials20

Sunday, March 6, 2011

Page 21: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

The  KEY  Python  Feature•Object  Oriented  Programming  (OOP)–  Classes  and  Instances–  Data  AbstracKon  and  EncapsulaKon–  Inheritance–  Polymorphism

•Complicated  at  first,  but  scales  to  very  powerful21

Sunday, March 6, 2011

Page 22: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Summary  Python  v.  MEL

•String  Methods

•Clean  /  readable• Lists,  arbitrary  nesKng• Logging•OOP  /  Classes

22

Sunday, March 6, 2011

Page 23: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

–Use  Case  -­‐  cvxporter• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion 23

Sunday, March 6, 2011

Page 24: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  cvxporter

•DirectX  .x  file  exporter  -­‐  Chad  Vernon–Great  example  of  vertex  scraping

–Lots  of  OpenMaya  and  Python  wrapped  API

–Nice  use  of  Classes  for  data  containers–Pro-­‐level  code  yet  very  applicable  and  easy  to  reverse  engineer

–hUp://www.chadvernon.com/blog/resources/cvxporter/24

Sunday, March 6, 2011

Page 25: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

25

Sunday, March 6, 2011

Page 26: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Use  Cases26

Sunday, March 6, 2011

Page 27: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

PYTHON  =  .5    PYMEL=1.0

•Get  Serious,  commit  to  PyMEL–Autodesk  blesses–Not  compiled

–Open  source•Add  to  it•Contribute  to  it

–Free27

Sunday, March 6, 2011

Page 28: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Maya’s  languages

•MEL  =  Maya  Embedded  Language

•Maya  Python  (maya.cmds)  =  MEL  wrapped  in  Python,  sKll  command  based

•PyMEL  =  Pythonic  Maya  Langauge

28

Sunday, March 6, 2011

Page 29: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Commands  v.  Objects• Key  difference–maya.cmds  is  MEL  in  disguise  (more  white-­‐spaces)

command  -­‐flag  object

–PyMEL  is  OOP,  based  on  Classesobject.func:on(flag)

29

Sunday, March 6, 2011

Page 30: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# creation of a joint object

# Perform a method on the instance object

myJoint = Joint()

myJoint.listRelatives()

Classes/OOP

•Class,  Instance,  Method–Create  object  of  ‘Joint’  class

30# Result: ‘root’ #

Sunday, March 6, 2011

Page 31: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

• ‘Pythonic’  difference  is  the  most  important–All  perKnent  commands/funcKons  are  anached  to  a  node  as  a  method

–IDE  w/  Code-­‐compleKon  lists  all  methods

–or  use  dir(node)  to  get  the  full  list

dir(myJoint)

for method in dir(myJoint): print method

Func4ons  as  Methods

31

# or a nice list

Sunday, March 6, 2011

Page 32: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# maya.cmds

# PyMEL object with method

# or one of PyMEL’s convenience functions (methods)

cmds.listRelatives(myJoint, parent=1)

myJoint.listRelatives(parent=1)

myJoint.getParent()

Func4ons  as  Methods

•example,  more  readable

32# Result: ‘root’ #

Sunday, March 6, 2011

Page 33: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Readability  (PEPs  8  &  20)

•The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts.

...

33

Sunday, March 6, 2011

Page 34: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

ac = AnimCurve(‘COG_translateX’)firstFrame = ac.getTime(0)lastFrame = ac.getTime(ac.numKeys()-1)

last = cmds.keyframe(‘COG_translateY’, q=1, kc=1)firstFrame = cmds.keyframe(‘COG_translateY’,index=(0,0), q=True)lastFrame = cmds.keyframe(‘COG_translateY’, index=(last-1,last-1), q=True)

# PyMEL

# maya.cmds

Func4ons  as  Methods•example:  animCurve–PyMEL  class  derived  from  maya.OpenMayaAnim.MFnAnimCurve

34

Sunday, March 6, 2011

Page 35: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

int $last = `keyframe -q -kc “COG_transalteY”`;float $firstFrame[] = `keyframe -index 0 -q “COG_translateY”`;float $lastFrame[] = `keyframe -index ($last-1`) -q “COG_translateY”`;

last = cmds.keyframe(‘COG_translateY’, q=1, kc=1)firstFrame = cmds.keyframe(‘COG_translateY’,index=(0,0), q=True)lastFrame = cmds.keyframe(‘COG_translateY’, index=(last-1,last-1), q=True)

# MEL

# maya.cmds

maya.cmds  =  MEL  in  disguise

35

Sunday, March 6, 2011

Page 36: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# maya.cmds

# PyMEL

transX = cmds.getAttr(‘%s.tx’ % myJoint)

transX = myJoint.tx.get()

AUribute  Access

•Super  fast

36

Sunday, March 6, 2011

Page 37: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

API  Hybridiza4on

•PyNodes  keep  API  dagPath–PyMEL  nodes  are  based  on  Maya’s  API  dagPaths  (“name-­‐independent  representaKon”)  so  your  node  maintains  its  whereabouts  no  maner  how  your  hierarchy  gets  re-­‐ordered.

–Very  handy  for  rigging–No  worries  on  bizarre  shapeNode  names

37

Sunday, March 6, 2011

Page 38: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# maya.cmds import maya.mel as mm

# or

# PyMEL

mm.eval(“skinWeightsIO -p \”” + path + “\” -m 0;”)

mm.eval(‘skinWeightsIO -p ”%s” -m 0;’ % path)

mel.skinWeights(p=path, m=0)

MEL  call  wrapper•makes  MEL  calls  act  like  a  funcKon  instead  of  eval

38

Sunday, March 6, 2011

Page 39: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# PyMELfrom pymel.internal.plogging import pymelLogger

pymelLogger.info(‘Regular user info here’)pymelLogger.warning(‘Colored output’)

PyMEL  logging  in  Maya

• internal.plogging  module–Fixes  Maya’s  Output  bug  for  logging

–pymelLogger  convenience  object

39

Sunday, March 6, 2011

Page 40: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# PyMELfrom pymel.tools import loggingControlloggingControl.initMenu()

PyMEL  logging  in  Maya

• loggingControl  module–Adds  Logging  Control  menu  to  Maya

–easy  access  to  all  logging  levels,  streams,  etc.

40

Sunday, March 6, 2011

Page 41: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

41

Sunday, March 6, 2011

Page 42: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# PyMELwin = window(title="My Window")layout = horizontalLayout()for i in range(5): button(label="button %s" % i)layout.redistribute() # now will redistribute horizontallywin.show()

PyMEL  UI•uitypes  module–  Layout  class–  window  class

42

Sunday, March 6, 2011

Page 43: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

43

Sunday, March 6, 2011

Page 44: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

# joint(n=”root”)

# PyMELimport pymel.tools.mel2py as mel2pymel2py.mel2pyStr(‘joint -n “root”;’)

MEL  to  python  translator

•pymel.tools.mel2py–Converts  enKre  scripts/directories

–converts  passed  string

44

Sunday, March 6, 2011

Page 45: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Performance

•Speed  disadvantage–wraps  maya.cmds  and  maya.OpenMaya•Lots  of  conversion  from  string  to/from  MObject

–Shows  itself  during  heavy  vertex  iteraKon

•Very  small  price  to  pay

45

Sunday, March 6, 2011

Page 46: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Performance

•Addressing  the  issue–Educate  users  on  efficient  pracKces

–Add  features  to  avoid  waisted  conversions

–Profile  and  collect  data

–Working/lobby  with  Autodesk

46

Sunday, March 6, 2011

Page 47: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

–Use  Case  -­‐  Pythonized  MetaNetwork

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion 47

Sunday, March 6, 2011

Page 48: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  Pythonized  MetaNetwork

•MetaRigging  Concept  -­‐  David  Hunt/Seth  Gibson–“Modular  Procedural  Rigging”  -­‐  GDC  2009

–Toolkit  is  open  source  MEL

–Convert  to  Python–Convert  to  Class/Method  structure

–Create  new  PyMEL/Maya  node  type  ‘MetaNetwork’•Sub-­‐classing  nt.Network  using  PyMEL’s  registerVirtualClass

48

Sunday, March 6, 2011

Page 49: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Use  Cases49

Sunday, March 6, 2011

Page 50: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Integrated  Development  Environment

•Commit  to  Serious  Dev  Soqware

•Need  REAL  features  like:–auto-­‐compleKon

–code  analysis–version  control

50

Sunday, March 6, 2011

Page 51: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse  as  IDE  w/  PyDev

•Open-­‐source  is  totally  viable•Eclipse  is  free–open  source–very  popular–tons  of  add-­‐ons,  plug-­‐in  SDKs•PyDev  plug-­‐in  turns  Eclipse  into  Python  powerhouse  (pydev.org)

51

Sunday, March 6, 2011

Page 52: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Mark  Occurrences

•Best  feature  possible•Fastest  way  to  see  what  is  happening  to  your  variable

–(demo)

52

Sunday, March 6, 2011

Page 53: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

53

Sunday, March 6, 2011

Page 54: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Code  Comple4on

•Combine  with  Class  based  methods  of  PyMEL  gives  you  nearly  any  possible  acKon  or  query  you  would  want  to  do  on  that  object

•  SUPER  POWERFUL!

–(demo)  

54

Sunday, March 6, 2011

Page 55: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

55

Sunday, March 6, 2011

Page 56: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Tool  Tips

•preview  window  into  the  full  funcKon• jump  to  funcKon

–(demo)

56

Sunday, March 6, 2011

Page 57: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

57

Sunday, March 6, 2011

Page 58: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Auto  impor4ng

• ‘context-­‐insensKve’  code  compleKon

•bring  up  pythonpath  and  automaKcally  import

–(demo)

58

Sunday, March 6, 2011

Page 59: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

59

Sunday, March 6, 2011

Page 60: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Code  Analysis

•Pydev  finds–Undefined/Unused  variables/imports

–No  ‘self’  token  in  class  methods

–Mixed/bad  indentaKon

–syntax  errors

•All  on  the  fly,  while  you  are  coding–(demo) 60

Sunday, March 6, 2011

Page 61: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

61

Sunday, March 6, 2011

Page 62: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Outliner

•Real  Outliner–Shows  everything–Hierarchy–Icons–“Bells  and  whistles”

–(demo) 62

Sunday, March 6, 2011

Page 63: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

63

Sunday, March 6, 2011

Page 65: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Real-­‐4me  debugging

•  Can  remotely  debug  Maya  with  Eclipse–Not  ideal  implementaKon

–Missing  some  key  features  that  WingIDE  has

–hnp://pydev.org/manual_adv_remote_debugger.html

65

Sunday, March 6, 2011

Page 66: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Eclipse:  Summary

• It’s  about  the  ‘Environment’

•Aware  of  code  base• Jumps  to  funcKons

•Knows  what  methods  are  available

• It’s  a  very  fast  way  to  program•A  professional’s  tool

66

Sunday, March 6, 2011

Page 67: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev–Use  Case  -­‐  RigClasses

• Wing  IDE  as  Debugger

• Conclusion 67

Sunday, March 6, 2011

Page 68: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  RigClasses•Turn  rig  components  into  inherited  Class  structure–Start  w/  basic  rigging•FK  Control

–Work  way  to  more  advanced•Simple  FK  Chain

• IK  Chain•Specific  IK  Chain 68

Sunday, March 6, 2011

Page 69: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

69

Base  Control

Use  Case  -­‐  RigClasses

Basic  Chain

FK  Chain IK  Chain

IK/FK  Chain

Basic  Leg

Biped  Leg Quad  Leg

Sunday, March 6, 2011

Page 70: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion70

Sunday, March 6, 2011

Page 71: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing  IDE

•Python-­‐only  IDE•Nice  features•Though  clunky•Might  just  need  Wing

•Can  use  both  Wing  and  Eclipse

•  $180  -­‐  pro  version71

Sunday, March 6, 2011

Page 72: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing’s  Killer  App

•Real-­‐Kme  debugging

–Change  your  life  as  a  Maya  Python  programmer

–Impossible  to  describe  how  valuable  a  feature  this  is

72

Sunday, March 6, 2011

Page 73: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Debugging  the  old  way

•Sucks• Lots  of  print  statements

•UI  prompts

•Way  too  slow

73

Sunday, March 6, 2011

Page 74: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Real-­‐4me  debugging

•Start  Wing  and  Maya

•Establish  connecKon•Set  breakpoint  in  script•Call  script  from  Maya

•Wing  grabs  the  process  and  halts  Maya

• (demo)74

Sunday, March 6, 2011

Page 75: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

75

Sunday, March 6, 2011

Page 76: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Maya  debugger•Break-­‐points•Watch  variables

•Debug  probe–autocomplete

–see  what  methods  are  available  at  runKme

•Call  stack–see  what  funcKons  led  to  current  spot 76

Sunday, March 6, 2011

Page 77: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

77

Sunday, March 6, 2011

Page 78: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Maya  debugger•Stack  data–current  state  of  data  at  that  moment  in  code

–updates  as  you  traverse  up  and  down  call  stack•allows  you  to  see  value  of  variable  as  it  passes  through  funcKons

–Ability  to  reverse  engineer  obscure  classes  via  instanKated  objects

–Can  change/update  in  realKme 78

Sunday, March 6, 2011

Page 79: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

79

Sunday, March 6, 2011

Page 80: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Maya  debugger

•Normally  Maya  process  is  frozen

•Refresh  trick–Put  ‘refresh()’  command  in  your  Watch  list  in  Wing

–You  can  watch  maya  update  as  you  step  though  line  by  line

80

Sunday, March 6, 2011

Page 81: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Features

•Unit  TesKng  Tool–Convenient  grouping–Easy  icons–Clear  results–Run  test  in  debug  mode!

81

UnitTesting works well in Eclipse too but Wing’s testing tools really flow well and you’ll probably need to debug anyway, so you might as well be using Wing.

Sunday, March 6, 2011

Page 82: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Wing:  Summary

•Want  professional  coder’s  features–debugging,  break-­‐points,  stack-­‐trace,  etc.

•Wing’s  Real-­‐Kme  debugging  is  huge–Single  most  import  ability!

–Allows  you  to  iterate  quickly82

Sunday, March 6, 2011

Page 83: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

–Use  Case  -­‐  RigClasses  combined  with  Pythonized  MetaNetwork

• Conclusion 83

Sunday, March 6, 2011

Page 84: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  RigClass  Embedded  MetaNetwork  

•MetaNodes  are  brains  for  rig  components

–Have  connecKons  to  each  part  of  that  rig  bit• Connect  all  the  MetaNodes  to  a  central  brain

–Nervous  system  for  the  enKre  rig

• Code  to  build  rig  component  is  an  instanKated  class

• Instance  has  tons  of  anributes  and  possibly  plenty  of  uKlity  methods  to  tweak,  change  the  rig

84

Sunday, March 6, 2011

Page 85: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  RigClass  Embedded  MetaNetwork  • Instance  is  gone  as  soon  as  build  code  is  complete

•What  if?–Embed  that  instanKated  object  into  the  MetaNode  for  that  rig  component

–AnyKme  look  at  MetaNode,  retrieve  the  instance  (re-­‐create  it?)

–  run  a  method  on  retrieved  instance•Delete  rig,  change  it,  re-­‐create  it 85

Sunday, March 6, 2011

Page 86: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Use  Case  -­‐  RigClass  Embedded  MetaNetwork  •Can  it  be  done?

–Impossible  in  MEL

–Must  use  PyMEL  and  Classes

–Need  environment  aware  IDE

–Must  have  Real-­‐Kme  debugging

86

Sunday, March 6, 2011

Page 87: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Outline• Background• Poll• Takeaway• Maya  Embedded  Language  (MEL)  v.  Python  (maya.cmds)

• PyMEL  v.  maya.cmds

• Eclipse  IDE  and  PyDev• Wing  IDE  as  Debugger

• Conclusion87

Sunday, March 6, 2011

Page 88: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Conclusion• Top  3  important  moments  in  DCC  apps  in  last  12  years:

–Maya  release•built  with  MEL

–Maya  supports  Python•really  PyMEL’s  implementaKon

–Advanced  Debugging•Eclipse  is  powerful•Wing’s  Real-­‐Kme  connecKon  to  Maya  =  godsend 88

Sunday, March 6, 2011

Page 89: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Thanks

•ChrisKan  Akesson,      @cakesson33

•Seth  Gibson,      @voMethod

•Eric  Pavey,      www.akeric.com•Chad  Vernon•@riggingdojo

89

Sunday, March 6, 2011

Page 90: Power&Python&Development for&Maya€¦ · for&Maya JasonParks Technical&Ar:st SonyOnlineEntertainment Sunday, March 6, 2011. Outline •Background •Poll •Takeaway •MayaEmbedded3Language3(MEL)3v.3Python3(maya.cmds)

Ques4ons?

•Twiner:  @count_zer0

•Email:  [email protected]

90

Sunday, March 6, 2011