Stumbling Toward 'Awesomeness'

A Technical Art Blog

Saturday, April 21, 2012

Maya: Walking the Line

I am still finding my feet in Maya, on my project, some files have grown to 800mb in size. Things get corrupt, hand editing MAs is common; I am really learning some of the internals.

In the past week I have had to do a lot of timeline walking to switch coord spaces and get baked animations into and out of hierarchies. In 3dsMax you can do a loop and evaluate a node ‘at time i’, and there is no redraw or anything. I didn’t know how to do this in Maya.

I previously did this with looping cmds.currentTime(i) and ‘walking the timeline’, however, you can set the time node directly like so: cmds.setAttr(“time1.outTime”, int(i))

Unparenting a child with keyed compensation (1200 frames)
10.0299999714 sec – currentTime
2.02 sec – setAttr

There are some caveats, whereas in a currentTime loop you can just cmds.setKeyframe(node), I now have to cmds.setKeyframe(node, time=i). But when grabbing a matrix, I don’t need to pass time and it works, I don’t think you can anyway.. I guess it gets time from the time node.

Here’s a sample loop that makes a locator and copies a nodes animation to world space:

#function feeds in start, end, node
	if not start: start = cmds.playbackOptions(minTime=1, q=1)
	if not end: end = cmds.playbackOptions(maxTime=1, q=1)
	loc = cmds.spaceLocator(name='parentAlignHelper')
	for i in range(start, (end+1)):
		cmds.setAttr("time1.outTime", int(i))
		matrix = cmds.xform(node, q=1, ws=1, m=1)
		cmds.xform(loc, ws=1, m=matrix)
		cmds.setKeyframe(loc, time=i)
posted by admin at 11:44 AM  

4 Comments »

  1. Hello Chris

    First you can read an attribute value at a different time context…
    just like 3dsmax:

    jointToBake = ‘joint5’ #its better to use the full path : |joint1|..|joint5
    matrixValue = cmds.getAttr(‘%s.worldMatrix’%jointToBake,t=30)

    (no need to hack this poor time node)

    Or just a quick tip about an alternate way of doing this:

    # how about using node to do space swtiching?
    cmds.loadPlugin(‘decomposeMatrix’)
    decmpMat=cmds.createNode(‘decomposeMatrix’)

    jointToBake = ‘joint5’ #its better to use the full path : |joint1|..|joint5
    cmds.connectAttr(‘joint5.worldMatrix’,decmpMat+’.inputMatrix’ ,f=True)

    worldSpaceBakeResultloc = cmds.spaceLocator()[0]
    ouputList = (‘.outputTranslate’,’.outputRotate’,’.outputScale’)
    channelList = (‘.t’,’.r’,’.s’)

    #just link the outputAttribute of the decomposeMatrix node to the locator
    for i in range(3):
    cmds.connectAttr(decmpMat+ouputList[i],loc+channelList[i],f=True)

    #one intersting thing is that you can create as many decomposeMatrix node, bakeLocator and then let maya do the work

    #notice the important flag: simulation=True
    #notice the list of object
    #I have done a test with startTime = 1 , endTime = 48
    cmds.bakeResults( [worldSpaceBakeResultloc,worldSpaceBakeResultlocN], sb=1,t=(1,48), at=[“rx”,”ry”,”rz”,”tx”,”ty”,”tz”],simulation=True)

    Comment by cedricB — 2012/04/21 @ 1:15 PM

  2. Thanks cedric, so many things I didn’t know about here. Like .worldMatrix I guess since the first time I saw a script getting a matrix with xform I thought that was the way, thanks for this!

    I guess bakeResult is better because it disconnects any constraints or things, also that simulation flag is good, I had used keys>bake simulation before.

    Re: decomposeMatrix – WTF, why is this a plugin and off by default? This could also be useful for switching things with a choice node. I will start using this more often, all Mayas have this?

    I will go back and rewrite my parent and unparent with compensation methods now 🙂 Thanks a lot!

    Comment by admin — 2012/04/21 @ 5:57 PM

  3. No problem Chris,

    In 3dsmax, we can script and play with object properties( when exposed )
    and also use their interface.

    In maya most of the time we can read and write a node attribute( the node documentation exposes what is possible to do with these attributes )

    decomposeMatrix: a little piece of gem, much like pointMatrixMult or vectorProduct nodes. I guess this is not a standard node ( like the closestPointOnSurface ) but was so useful that they compile it now and include it in maya.

    Don’t know if it is true for linux or mac environment .
    Good luck for your work.

    Comment by cedricB — 2012/04/22 @ 10:22 AM

  4. Awesome blog article.Much thanks again. Fantastic.

    Comment by Myla Pyne — 2012/08/03 @ 1:58 PM

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress