Due to a miscommunication between Elsevier Press and the Python Software Foundation, the first printing of this title used an unauthorized modification of the trademarked Python logo. We apologize to the PSF for this, and they have been understanding of our in-press status; in the 2nd and subsequent printing of this title, we shall use a cover design that has been approved as non-dilutive by the Python Software Foundation.

Help make the world a better place and make a secure donation to the Python Software Foundation today!

 

Chapter 11

Data Flow in Maya

Author

Adam Mechtley

Project

Examine visual data flow charts that represent how data is transmitted in Maya, explore the DG and DAG in the Hypergraph, debug DG

Example Files

None

Synopsis

This chapter explains Maya’s dependency graph architecture in great detail. It provides examples of how messages and data are propagated throughout the dependency graph, how nodes operate on the data, and what ramifications this structure has. Readers will examine a variety of diagrams to help visualize how data is transmitted in Maya.

Resources

None

Other Notes

None

Errata for the First Edition

None


5 Responses to “Chapter 11”

  1. I was trying to use the MTransformationMatrix to set the shear for a sphere. It doesn’t seem to work. Please let me know what’s wrong with the script. Thanks!

    import maya.cmds as cmds
    import maya.OpenMaya as om

    sphere1 = cmds.polySphere(r=1)
    sel = om.MSelectionList()
    sel.add(sphere1[0])
    path = om.MDagPath()
    sel.getDagPath(0, path)
    path.extendToShape()
    print(path.fullPathName())

    fn = om.MFnDagNode(path)
    matrix = om.MTransformationMatrix(fn.transformationMatrix())
    util = om.MScriptUtil()
    util.createFromDouble(1.2, 3.2, 2.4)
    ptr = util.asDoublePtr()
    matrix.setShear(ptr, om.MSpace.kTransform)

    • Hi Serena,

      There are actually three things worth noting in this case. First, note that an MTransformationMatrix is just a container for data here. You have to use the function set to actually apply changes to the object. That said, you need to use a descended class, MFnTransform, to actually apply changes to an object’s transformation matrix in the scene. Third, MFnTransform is not compatible with shape nodes, so it must be passed a transform node. If you wanted to shear the raw vertices in the shape node, you could pass the shape node to an MFnMesh function set and would have to manually multiply vertex positions by your desired shearing matrix. In this case, I would rewrite your example in the following way:

      import maya.cmds as cmds
      import maya.OpenMaya as om
      sphere1 = cmds.polySphere(r=1)
      sel = om.MSelectionList()
      sel.add(sphere1[0])
      path = om.MDagPath()
      sel.getDagPath(0, path)
      fn = om.MFnTransform(path)
      util = om.MScriptUtil()
      util.createFromDouble(1.2, 3.2, 2.4)
      ptr = util.asDoublePtr()
      fn.setShear(ptr)

      • Ok I see. Thank you!

        Do you have any advice in reading through the API documentation? In the MTransformationMatrix there’s a getShear and a setShear so I interpreted it as the setShear would change the shear value for a given piece of geometry.

        • The real key is understanding how data in the Maya scene are protected, and how the API is organized around this paradigm. Basically, if you want to manipulate an object in the scene, you’ll generally always need to use an interface like a function set (refer to e.g., MFnBase class), a plug (MPlug), or a data handle (MFnDataHandle).

          The particular clue in this case though is that the function transformationMatrix() is simply returning an MMatrix object, which is a copy of the object’s transformation matrix. As such, it has no particular linkage back to the source from which it came (i.e., it is not a reference). It is analogous to doing getAttr on a node in the scene and storing the value in a variable. While the value you retrieved may have methods associated with it, altering the value in the variable has no effect on the attribute on original object.

          The MTransformationMatrix class is basically a more fully-featured MMatrix, and contains a variety of methods common to transforming geometry, which wouldn’t necessarily make sense for a general-purpose matrix. In this case, you might use an MTransformationMatrix if you wrote a shear deformer, for instance. In such a case, the user could input some shear values and you would then use them to construct a deformation matrix with which you would multiply each point in the geometry being deformed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.