Mel has the
Enter the API. The
Pseudo code to use it:
polyColorPerVertex
command, that will change the color of one vertex at a time. This works fine you're doing it on less than 100 verts at a time. But on more than 1000, it really starts to slow down.Enter the API. The
MFnMesh
class has a setVertexColors
method which allows you to set multiple colors at once. And it is much faster.Pseudo code to use it:
import maya.OpenMaya as om # Build an empty vertex ID array: idArray = om.MIntArray() # Now fill it with the vert ID's on the object to color. # Could be some, or all of them. # Build an empty color array: colorArray = om.MColorArray() # Now fill it with the colors for each of the vert ID's # defined above. # Get a MDagPath for the object we're coloring: selList = om.MSelectionList() selList.add(myObject) mDagPath = om.MDagPath() selList.getDagPath(0, mDagPath) # Get a MFnMesh for our object: mFnMesh = om.MFnMesh(mDagPath) # Apply the colors: mFnMesh.setVertexColors(colorArray, idArray)It should be noted that since you're using the API to modify the scene graph, there is no undo available. To get undo, you'd need to author this as a scripted plugin command.