Thursday, September 4, 2014

Resetting controller's transform with pymel

A tricky way to reset ctrl transform is to multiply the ctrl and the parent group matrices together and put the result to the parent then zero out ctrl transform. Whola! You got zeroed out ctrl where you put it.

#############################################
import pymel.core as pm
import maya.OpenMaya as om

def resetChannelBox(obj):
cbAttr = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz']
for a in cbAttr:
attr = obj.attr(a)
locked = False

if attr.isLocked() == True and obj.isReferenced() == False:
attr.unlock()
locked = True
try:
if 's' in a:
attr.set(1.00)
else:
attr.set(0.00)
except:
return False

if locked == True:
attr.lock()

return True


def resetCtrlTransform(objs=[]) :
if not objs:
objs = pm.selected(type='transform')
if not objs:
return

for obj in objs:
offsetGrp = obj.getParent()
if not offsetGrp:
om.MGlobal.displayWarning('%s  has no parent. Continue.' %obj.nodeName())
continue

srcMtx = obj.getMatrix()
grpMtx = offsetGrp.getMatrix()
resultMtx = srcMtx * grpMtx

offsetGrp.setMatrix(resultMtx)
resetChannelBox(obj)

if isinstance(obj, pm.nt.Joint) == True:
obj.jointOrient.set([0.0, 0.0, 0.0])


resetCtrlTransform()

Tuesday, September 2, 2014

Average Vertex Skin Weight Brush!

    A custom brush for smoothing skin weight. It takes its surrounding vertices weights and blend it to the original weights. The result is kinda like hammer weight tool, but with brush you can paint on.

    Base on the original 'tf_smoothSkinWeight.py' by Tom Ferstl posted on createivecrash.com
I did a little modification. The brush now performs a little faster and supports undo/redo.
Please see: creative crash link


How to use  : 1.Put averageVertexSkinWeightCmd.py to your plugin path.
                         (ie. C:\Program Files\Autodesk\maya<Version>\bin\plug-ins)
                      2.Put averageVertexSkinWeightBrush.py to your python path.
                         (ie. C:\Documents and Settings\<username>\My Documents\maya\<Version>\scripts)
                      3.Execute the following python command.

import averageVertexSkinWeightBrush
averageVertexSkinWeightBrush.paint()

Enjoy!
DOWNLOAD