Custom node to set vertex color based on geometry information

Custom node to set vertex color based on geometry information

IW_09
Explorer Explorer
536 Views
0 Replies
Message 1 of 1

Custom node to set vertex color based on geometry information

IW_09
Explorer
Explorer

Hi. I'm new to Maya and am still learning the basics, so apologies if this question is all over the place. I want to write a custom node that controls the mesh's vertex colour based on its geometric information (normal, curvature, displacement from another mesh, etc). I noticed that the 

polyColorPerVertex command creates a node that connects to the mesh attribute rather than ColorPerVertex or ColorSet, so I tried to do the same. But when I try this in the compute method

 

# In initialize()
gattr = om.MFnGenericAttribute()
cls.mesh_obj = gattr.create("Mesh", "mesh")
gattr.addDataType(om.MFnData.kMesh);			
gattr.keyable = True
gattr.readable = False
gattr.writable = True

# In compute()
mesh = data.outputValue(plug).asMesh()
mesh_fn = om.MFnMesh(mesh)

 

Maya raises the error "object is incompatible with MFnMesh constructor". I don't know if this is because I used MFnGenericAttribute instead of MFnTypedAttribute, so I switched to a deformer node (because it seems that MFnTypedAttribute in DependNode cannot be connected to InMesh/OutMesh of the shape node - yet another thing I don't understand). I can successfully create a mesh function set, so I tried

 

 

mesh_fn.setVertexColors(colors, indices) # colors: MColorArray, indices:MIntArray

 

 

which doesn't raise any error, but doesn't take any effect on the colour either. I'm not sure what to do now and would appreciate it if anyone can point me to the right direction.

0 Likes
537 Views
0 Replies
Replies (0)