::changing skeleton after binding::

December 5th, 2009 by hamish download the zooToolBox

sometimes I just feel slow – I expect alot of you already know this, but its new to me – and super useful.  just say you’ve skinned up your dude and spent a bunch of time getting things looking sha-weet! and you suddenly realize that where you placed the clavicles is kinda dumb.

well of course, you could use maya’s move joint without affecting skin tool, but its a bit of a shit tool imho – its super clunky, you can’t do things like rotate freeze transform etc – it simply lets you move.  you could *also* use something like zooWeightSave to store weights, blow weights away, change skeleton reapply weights…  but gah!  thats more than one step!

anyhoo, so the following script will take the current pose of the skeleton and redefine it as the bind pose, and resets the skin.  nothing else is changed, so your weighting etc is untouched.  in fact the skin cluster doesn’t even need to be turned off.

import maya.cmds as cmd
import maya
def resetSkinCluster( skinCluster ):
	'''
	splats the current pose of the skeleton into the skinCluster - ie whatever
	the current pose is becomes the bindpose
	'''
	nInf = len( cmd.listConnections( '%s.matrix' % skinCluster, destination=False ) )
	for n in range( nInf ):
		try:
			slotNJoint = cmd.listConnections( '%s.matrix[ %d ]' % (skinCluster, n), destination=False )[ 0 ]
		except IndexError: continue

		matrixAsStr = ' '.join( map( str, cmd.getAttr( '%s.worldInverseMatrix' % slotNJoint ) ) )
		melStr = 'setAttr -type "matrix" %s.bindPreMatrix[ %d ] %s' % (skinCluster, n, matrixAsStr)
		maya.mel.eval( melStr )

		#reset the stored pose in any dagposes that are conn
		for dPose in cmd.listConnections( skinCluster, d=False, type='dagPose' ) or []:
			cmd.dagPose( slotNJoint, reset=True, n=dPose )

anyway, I actually use this as a step in our auto-rigger.  basically before a skeleton is auto-rigged, it gets checked to ensure alignment of everything is kosher – and if not it fixes things up and resets the bind pose.  so modelers and animators don’t have to worry about joint alignment, they just need to worry about placement (which is much easier to get right), and alignment is taken care of auto-magically.  placement can also be changed just as easily – because the rig is auto generated they can change the placement of a clavicle and hit auto-rig and the clav placement gets updated and the rig rebuilt to suit.

anyway – its an awesome time saver.  I plan to write functionality that will emulate maya’s crappy joint re-placement tool. but it’ll be state based: so turn skin off, change skel with any normal maya tools (freeze transforms as well) then re-enable skinning.

Share

This post is public domain

This entry was posted on Saturday, December 5th, 2009 at 08:12 and is filed under tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

  • Ultra

    I try to run your script and I get // Error: Invalid use of Maya object “skinCluster”.

  • hamish

    Sorry – I made a few assumptions in the code. I’ve changed it slightly so that it should run as is – just copy and paste the code snippet into a python script tab in maya, and then run the python command:
    resetSkinCluster( ‘skinCluster1′ )

    or whatever the name of the skin cluster is, and it should work.

  • http://www.facebook.com/x900lbGorillax Mark Palcko

    Excellent tool! Thank you!