python - maya.api.openMaya setWeight not calling right version of function -
i'm not including supplementary files use track maya nodes, if see attr, know it's way track dags/mobjects pass variables , find paths , attributes of tracked nodes. polygon , polygonshape similar classes inherit node tracking method specific types of nodes. code them further in file, i'm excluding code not make longer needs be. suffice say, tracks polygon dag , polygonshape mobj.
here's problem.
# error: line 1: typeerror: file d:/libraries/my documents/maya/scripts\toolbox\shapes.py line 332: integer required #
the line 332 setweight line @ bottom.
using code, can weights , break them apart verts seemingly fine, when try setweights, says needs int variable. int variable refers vert vert version of setweight method. reason it's not accepting variables i'm submitting , reverting wrong method. i've checked types going method. correct. checked length of influences , length of weights correct. since they're right type , right length, i'm left assume it's self.vertexcomp, mobject worked correctly get, , i've seen versions of setweights used exact same method.
can @ , see causing setweight error:
import maya.cmds cmds import attributor attr #custom package interact nodes import maya.api.openmaya om import maya.api.openmayaanim omanim class skincluster(attr.node): outputgeometry = attr.connection("outputgeometry") def getinfl_ids(self,dagobj=false,pathfirst=false): infdags = self.skinfn.influenceobjects() infids = {} 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 {0:"joint1",1:"joint2"} # useful figuring out list indexes edit weight tools def __init__(self, nodename=none, tracker=none, vertices=none, shapenode=none): if not nodename , 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] x in range(0,len(weights),infcount)] dicty = {} i, weight in enumerate(weights): if not vertices or in vertices: dicty.update({i:weight}) return dicty # returns 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 verts going edited oldweights = self.getweights(vertices) #gets vert weights undo oldvalues = [] newvalues = [] influences = self.getinfl_ids().keys() # gets influence indices vert in vertices: oldvalues += oldweights[vert] # combine weights list newvalues += values[vert] # combines new weights list self.skinfn.setweights(self.polygon.tracker.dag, self.vertexcomp, om.mintarray(influences), om.mdoublearray(newvalues), normalize=normalize, oldvalues=om.mdoublearray(oldvalues))
while printing double check types, output:
<type 'openmaya.mdagpath'> <type 'openmaya.mobject'> <type 'openmaya.mintarray'> <type 'openmaya.mdoublearray'> <type 'bool'> <type 'openmaya.mdoublearray'>
source materials:
https://gist.github.com/utatsuya/a95afe3c5523ab61e61b
http://download.autodesk.com/us/maya/2010help/api/class_m_fn_skin_cluster.html#52071d6c77ca374a4c8723f0c63e90e5
found post similar issue, didn't appear help. maybe else notice why solutions work , i'm missing.
what found maya.api.openmayaanim setweight function it's not undoable. have steps make can undone, , that's pain. instead created fetches getweight values , uses skinpercent command set them.
@property def weights(self): vertweights = self.skinfn.getweights(self.polygon.tracker.dag, self.vertexcomp) weights = list(vertweights[-2]) infcount = vertweights[-1] weights = [weights[x:x + infcount] x in range(0, len(weights), infcount)] dicty = {} i, weight in enumerate(weights): dicty.update({i: weight}) # returns {vert1:[weightvalue0,weightvalue1,weightvalue2..],vert2:[etc..]} # weight list index corresponds influences self.getinfl_ids(), it's easy iterate weights using index. return dicty @weights.setter def weights(self, values): #will set verts sent it. uses same data structure influences = self.getinfl_ids() vert, weights in values.iteritems(): tempy = [] i, value in enumerate(weights): tempy += [(influences[i],value)] cmds.skinpercent(self.path, self.shapenode.getvertname(vert), transformvalue=tempy)
Comments
Post a Comment