Maya - Transferring weighted vertex colors via scripted node

python
maya

#1

Hi all,

I’m looking to create a tool to blend vertex colors from multiple input mesh onto a target mesh in real time, with a scripted node. I have a decent start on the attribute setup, but before sinking too much more time into this I’d like to ask if I’m heading in the right direction.

blendvertexcolors

For example, do I need to match all the sub-attributes of the “colorPerVertex” compound attr exactly for the attribute to “take” (as in adding all those faceVertex attrs, even if I don’t intend to use them).

I’d love to know if I’m going in the complete wrong direction too! Maybe there’s an easier way to do all this.

Thanks!


#2

Recreated the compound node construction and now the attribute connects! Hoping this is the start of a great plugin.

            ''' defines the input and output attributes as static varaibles in out plugin '''
        numAttrFn = om.MFnNumericAttribute()
        intArrayAttrFn = om.MFnGenericAttribute()
        doubleArrayAttrFn = om.MFnGenericAttribute()

        ''' input attributes '''
        cls.attrIn_tensionColor_01 = doubleArrayAttrFn.create( 'tensionColor_01', 'tc01' )
        cls.attrIn_tensionIndex_01 = intArrayAttrFn.create( 'tensionIndex_01', 'ti01' )
        
        cls.addAttribute( cls.attrIn_tensionColor_01 )
        cls.addAttribute( cls.attrIn_tensionIndex_01 )

        out_compAttrFn_parent = om.MFnCompoundAttribute()
        out_compAttrFn_child1 = om.MFnCompoundAttribute()
        out_compAttrFn_child2 = om.MFnCompoundAttribute()

        ''' output attribute '''
        cls.outputMeshAttribute = out_compAttrFn_parent.create( 'colorPerVertexOut', 'cpvo01' )
        cls.attrOut_vertexColor = out_compAttrFn_child1.create( 'vertexColorOut', 'vco01' )
        cls.attrOut_vertexColorRGB = numAttrFn.createColor( 'vertexColorRGBOut', 'vcrgbo01')
        cls.attrOut_vertexAlpha = numAttrFn.create( 'vertexAlphaOut', 'vao01', om.MFnNumericData.kFloat)
        
        cls.attrOut_vertexFaceColor = out_compAttrFn_child2.create( 'vertexFaceColorOut', 'vcfo01' )
        cls.attrOut_vertexFaceColorRGB = numAttrFn.createColor( 'vertexFaceColorRGBOut', 'vcrfgbo01')
        cls.attrOut_vertexFaceAlpha = numAttrFn.create( 'vertexFaceAlphaOut', 'vfao01', 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.outputMeshAttribute )
            
        # if any of the inputs change, the output mesh will be recomputed
        cls.attributeAffects( cls.attrIn_tensionColor_01, cls.outputMeshAttribute )
        cls.attributeAffects( cls.attrIn_tensionIndex_01, cls.outputMeshAttribute )