#print tensionColor
#print tensionIndex
#print blendWeight
try:
mergedVertColors = self.mergeVertColors( mergedVertColors, tensionColor, tensionIndex )
#print "Done", mergedVertColors
except:
multiInputArrayHandle.next()
continue
# next!
multiInputArrayHandle.next()
# this is ultra hacky
mesh = getBlendShapeMesh()
for index, color in mergedVertColors.items():
#print index
#print color
blendedValues = []
for i in color:
blendedValues.append( i * blendWeight )
blendedColor = om.MColor( blendedValues, model=om.MColor.kRGB, dataType=om.MColor.kFloat )
mesh.setVertexColor(blendedColor.getColor(), index)
# for some reason setVertexColor works but setVertexColors doesn't, arg
#mesh.setVertexColors( mergedVertColors.values(), mergedVertColors.keys() )
# is this plug actually dirty though? guess it can't hurt
dataBlock.setClean(plug)
def mergeVertColors(self, mergedColors, vertColors, vertIndices):
for color, index in zip(vertColors, vertIndices):
# make vectors
if color < 1:
color = om.MColor( [0, 0, color], model=om.MColor.kRGB, dataType=om.MColor.kFloat )
if color >= 1:
color -= 1
color = om.MColor( [color, 0, 0], model=om.MColor.kRGB, dataType=om.MColor.kFloat )
if index in mergedColors:
temp = mergedColors[index] + color
newColor = []
# clamp values to a max of 1
for i in temp:
if i >= 1:
newColor.append(i)
else:
newColor.append(1)
mergedColors[index] = newColor
else:
mergedColors[index] = color
return mergedColors
@classmethod
def nodeCreator(cls):
''' creates and instance of out node class and delivers to to maya as a pointer '''
return cls()
@classmethod
def nodeInitializer(cls):
''' defines the input and output attributes as static variables in our plugin '''
blendShapeMultiInput = om.MFnCompoundAttribute()
doubleArrayAttrFn = om.MFnGenericAttribute()
intArrayAttrFn = om.MFnGenericAttribute()
intAttrFn = om.MFnNumericAttribute()
''' input attributes '''
cls.attrIn_blendShapeMultiInput = blendShapeMultiInput.create( 'blendShapeMultiInput', 'mai' )
cls.attrIn_tensionColor_01 = doubleArrayAttrFn.create( 'tensionColor', 'tc' )
cls.attrIn_tensionIndex_01 = intArrayAttrFn.create( 'tensionIndex', 'ti' )
cls.attrIn_blendWeight = intAttrFn.create( 'blendWeight', 'bw', om.MFnNumericData.kFloat )
doubleArrayAttrFn.addDataType( om.MFnData.kDoubleArray )
intArrayAttrFn.addDataType( om.MFnData.kIntArray )
blendShapeMultiInput.array = True
blendShapeMultiInput.addChild( cls.attrIn_tensionColor_01 )
blendShapeMultiInput.addChild( cls.attrIn_tensionIndex_01 )
blendShapeMultiInput.addChild( cls.attrIn_blendWeight )
cls.addAttribute( cls.attrIn_blendShapeMultiInput )
"""
typedAttribute = om.MFnTypedAttribute()
cls.attrOut_outputMesh = typedAttribute.create("outMesh", "om", om.MFnData.kMesh, om.MObject.kNullObj )
cls.addAttribute( cls.attrOut_outputMesh )
### keeping this around because it took a lot of work to make ###
''' output attributes '''
numAttrFn = om.MFnNumericAttribute()
out_compAttrFn_parent = om.MFnCompoundAttribute()
out_compAttrFn_child1 = om.MFnCompoundAttribute()
out_compAttrFn_child2 = om.MFnCompoundAttribute()
cls.attrOut_colorPerVertex = out_compAttrFn_parent.create( 'colorPerVertex', 'cpvo' )
cls.attrOut_vertexColor = out_compAttrFn_child1.create( 'vertexColor', 'vco' )
cls.attrOut_vertexColorRGB = numAttrFn.createColor( 'vertexColorRGB', 'vcrgbo')
cls.attrOut_vertexAlpha = numAttrFn.create( 'vertexAlpha', 'vao01', om.MFnNumericData.kFloat)
cls.attrOut_vertexFaceColor = out_compAttrFn_child2.create( 'vertexFaceColor', 'vfco' )
cls.attrOut_vertexFaceColorRGB = numAttrFn.createColor( 'vertexFaceColorRGB', 'vcfrgbo')
cls.attrOut_vertexFaceAlpha = numAttrFn.create( 'vertexFaceAlpha', 'vfao', om.MFnNumericData.kFloat)
out_compAttrFn_parent.addChild( cls.attrOut_vertexColor )
out_compAttrFn_child1.array = True
out_compAttrFn_child1.addChild( cls.attrOut_vertexColorRGB )
out_compAttrFn_child1.addChild( cls.attrOut_vertexAlpha )
out_compAttrFn_child1.addChild( cls.attrOut_vertexFaceColor )
out_compAttrFn_child2.array = True
out_compAttrFn_child2.addChild( cls.attrOut_vertexFaceColorRGB )
out_compAttrFn_child2.addChild( cls.attrOut_vertexFaceAlpha )
cls.addAttribute( cls.attrOut_colorPerVertex )
"""
cls.attributeAffects( cls.attrIn_blendWeight, cls.attrIn_blendShapeMultiInput )
def initializePlugin( mobject ):
''' initliize the plug-in'''
mPlugin = om.MFnPlugin( mobject )
try:
mPlugin.registerNode( TensionMapBlender.nodeName, TensionMapBlender.nodeId, TensionMapBlender.nodeCreator, TensionMapBlender.nodeInitializer )
print "Loaded plugin"
except:
sys.stderr.write( 'Failed to register node: ' + TensionMapBlender.nodeName )
raise
def uninitializePlugin( mobject ):
''' uninitialize the plugin'''
mPlugin = om.MFnPlugin( mobject )
try:
mPlugin.deregisterNode( TensionMapBlender.nodeId )
print "Unloaded plugin"
except:
sys.stderr.write( 'Failed to deregister node: ' + TensionMapBlender.nodeName )
raise