Custom node to set vertex color based on geometry information
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
# 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.