Blend Skin weights “tool”

Hi,

So I wanted a blend between two “skinnings” of a characer we are working on for our game. I got so annoyed that Maya did not provide a feature for this, that I mocked up my own piece of code. Make sence of it if you can..

Warning not “production” strength code :-)

  
import pymel as pm
import copy

class skinMerger:
	
	def __init__(self, mesh, nrOfVerts=5000):
		"""class for merging meshes
		
		Usage could look like this:
		#mergeMachine = skinMerger('monster')
		mergeMachine.grabA()
		mergeMachine.grabB()
		mergeMachine.setTarget()
		"""
		
		self.mesh = mesh
		self.nrOfVerts = nrOfVerts
		self.src_A_weightList = []
		self.src_B_weightList = []

	def grabA(self):
		"""Grab the first skinning"""
		skinCluster = pm.mel.findRelatedSkinCluster(self.mesh)
		influences = pm.skinCluster(skinCluster, q=True, influence=True)		
		
		# Get the weights off the source mesh A
		for v_index in range(0, self.nrOfVerts):
		   self.src_A_weightList.append(pm.skinPercent(skinCluster, self.mesh+'.vtx['+str(v_index)+']', q=True, value=True))

	def grabB(self):
		"""Grab the second skinning"""		
		skinCluster = pm.mel.findRelatedSkinCluster(self.mesh)
		influences = pm.skinCluster(skinCluster, q=True, influence=True)		
		
		# Get the weights off the source mesh A
		for v_index in range(0, self.nrOfVerts):
		   self.src_B_weightList.append(pm.skinPercent(skinCluster, self.mesh+'.vtx['+str(v_index)+']', q=True, value=True))
	
	def setTarget(self, blendFactor=0.5):
		"""Set the final blended skinning"""
		skinCluster = pm.mel.findRelatedSkinCluster(self.mesh)
		influences = pm.skinCluster(skinCluster, q=True, influence=True)
		
		# Make the blended target list		
		merged_weightList = copy.deepcopy(self.src_A_weightList)
		for v_index in range(0, self.nrOfVerts):
		   for i_index in range(0, len(influences)):
		       merged_weightList[v_index][i_index] = (self.src_A_weightList[v_index][i_index]*(1-blendFactor)) + (self.src_B_weightList[v_index][i_index]*blendFactor)
		
		# Set the weights on the target mesh
		for v_index in range(0, self.nrOfVerts):
		   for i_index in range(0, len(influences)):
		       pm.skinPercent( skinCluster , (self.mesh + '.vtx[' + str(v_index) +']') , transformValue=[(influences[i_index], merged_weightList[v_index][i_index])] )
 
Friday, April 24th, 2009 Main

1 Comment to Blend Skin weights “tool”

  • Sune says:

    Wow Sune, this tool is pretty slow!!

    Regards,
    Sune (Myself)

  • Leave a Reply