pymel.core.animation.bakeDeformer

bakeDeformer(*args, **kwargs)

Given a rigged character, whose mesh shape is determined by a set of deformers, bakeDeformer calculates linear blend skin weights most closely approximating observed deformations. To do this, a test set of examples is generated by moving the rig through a range of motion. Results mesh and pose pairs are then used to solve a constrained optimization, solving for skinning weights. bakeDeformer automatically binds and applies resulting weights to the destination geometry. If the source and destination mesh/skeleton are identical, the command will replace the original deformations with a skinCluster and computed weights. See the below examples for sample usage.

Flags:

Long Name / Short Name Argument Types Properties
dstMeshName / dm unicode ../../../_images/create.gif
  The destination mesh name.
dstSkeletonName / ds unicode ../../../_images/create.gif
  The destination skeleton name.
maxInfluences / mi int ../../../_images/create.gif
  The maximum number of influences per vertex.
srcMeshName / sm unicode ../../../_images/create.gif
  The source mesh name.
srcSkeletonName / ss unicode ../../../_images/create.gif
  The source skeleton name. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.bakeDeformer

Example:

::

import pymel.core as pm

import maya.cmds as cmds import maya.mel as mel

def createJointsAndMesh(offset = (0., 0., 0.)):

root = pm.joint() for _ in range(0,5):

pm.joint() pm.move(0., 2., 0., r=True)

meshes = pm.polyCube(sx=3,sy=10,sz=3,h=10) pm.move(0, 5, 0, r=True) pm.select([root, meshes[0]], r=True) pm.move(offset[0], offset[1], offset[2], r=True) pm.select(cl=True) return (root, meshes[0])

def bindMesh(object):
rootJoint, mesh = object pm.select(rootJoint, r=True, hi=True) pm.select(mesh, add=True) mel.eval(‘SmoothBindSkin’) pm.select(cl=True)
def randomizeJoints(object):

from math import degrees rootJoint = object[0] pm.select(rootJoint, r=True) pm.pickWalk(d=’down’) for i in range(4):

rads = mel.eval(‘sphrand 1.’) pm.rotate(degrees(rads[0]), degrees(rads[1]), degrees(rads[2])) pm.pickWalk(d=’down’)
def matchRotations(src, dst):

pm.select(src[0], r=True, hi=True) srcChain = pm.ls(sl=True)

pm.select(dst[0], r=True, hi=True) dstChain = pm.ls(sl=True)

for joints in zip(dstChain, srcChain):
pm.select(list(joints), r=True) mel.eval(‘MatchRotation’)

# Create a new scene pm.file(f=True, new=True)

# Create two joint chains/meshes object1 = createJointsAndMesh() object2 = createJointsAndMesh(offset=(5, 0, 0))

# Bind one of the joint chains to the mesh and rotate the weights bindMesh(object1) randomizeJoints(object1)

# Use bakeDeformer to learn and apply the linear blend skinning weights. mel.eval(

‘bakeDeformer -ss {0[0]} -sm {0[1]} -ds {1[0]} -dm {1[1]} -mi 3’.format(object1, object2) )

# Match the rotations of the two chains to show the results are similar matchRotations(object1, object2)