Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Error: line 1: TypeError: file D:/Libraries/My Documents/maya/scriptstoolboxShapes.py line 332: an integer is required #
- import maya.cmds as cmds
- import Attributor as attr #custom package to interact with nodes
- import maya.api.OpenMaya as om
- import maya.api.OpenMayaAnim as omAnim
- class skinCluster(attr.node):
- outputGeometry = attr.connection("outputGeometry")
- def getInfl_IDs(self,dagObj=False,pathFirst=False):
- infDags = self.skinFn.influenceObjects()
- infIds = {}
- for x in xrange(len(infDags)):
- infPath = attr.joint(nodeName=infDags[x].fullPathName()) if dagObj else infDags[x].fullPathName()
- infId = int(self.skinFn.indexForInfluenceObject(infDags[x]))
- if pathFirst:
- infIds[infPath] = infId
- else:
- infIds[infId] = infPath
- return dict(infIds)
- # Returns something like {0:"joint1",1:"joint2"}
- # useful for figuring out what list indexes to edit with weight tools
- def __init__(self, nodeName=None, tracker=None, vertices=None, shapeNode=None):
- if not nodeName and vertices:
- nodeName = polygonShape(nodeName=vertices[0]).inMesh["in"][0]
- self.initialize(nodeName=nodeName, tracker=tracker)
- self.polygon = polygon(nodeName=self.outputGeometry["out"][0])
- self.shapeNode = shapeNode if shapeNode else polygonShape(nodeName=self.polygon.shapeNodes[0].path)
- self.skinFn = omAnim.MFnSkinCluster(self.tracker.obj)
- self.vertexComp = om.MFnSingleIndexedComponent().create(om.MFn.kMeshVertComponent)
- def getWeights(self, vertices=None):
- vertWeights = self.skinFn.getWeights(self.polygon.tracker.dag, self.vertexComp)
- weights = list(vertWeights[-2])
- infCount = vertWeights[-1]
- weights = [weights[x:x+infCount] for x in range(0,len(weights),infCount)]
- dicty = {}
- for i, weight in enumerate(weights):
- if not vertices or i in vertices:
- dicty.update({i:weight})
- return dicty
- # returns a vert weight list
- # {0:[0.1, 0.2, 0.3, 0.4], 1:[etc..]}
- def setWeights(self,values=None,normalize=True):
- vertices = values.keys() #gets all the verts that are going to be edited
- oldWeights = self.getWeights(vertices) #gets vert weights for undo
- oldValues = []
- newValues = []
- influences = self.getInfl_IDs().keys() # gets the influence indices
- for vert in vertices:
- oldValues += oldWeights[vert] # combine weights into a list
- newValues += values[vert] # combines the new weights to a list
- self.skinFn.setWeights(self.polygon.tracker.dag, self.vertexComp,
- om.MIntArray(influences), om.MDoubleArray(newValues),
- normalize=normalize, oldValues=om.MDoubleArray(oldValues))
- <type 'OpenMaya.MDagPath'>
- <type 'OpenMaya.MObject'>
- <type 'OpenMaya.MIntArray'>
- <type 'OpenMaya.MDoubleArray'>
- <type 'bool'>
- <type 'OpenMaya.MDoubleArray'>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement