Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.api.OpenMaya as om2
- import time
- startTime = time.time()
- # API get the mesh
- selList = om2.MGlobal.getActiveSelectionList()
- dagPath = selList.getDagPath(0)
- selMesh = om2.MFnMesh(dagPath)
- # Get vert list
- vertList = list(set(selMesh.getVertices()[1]))
- lenVertList = len(vertList)
- # Initial color info
- tempColor = om2.MColor([0.0,0.0,0.0])
- vertexColorList = om2.MColorArray(lenVertList, tempColor)
- # Get points and values
- pointsList = selMesh.getPoints(om2.MSpace.kWorld)
- pointsDirList = ([p[1] for p in pointsList])
- pMin = min(pointsDirList)
- pMax = max(pointsDirList)
- count = 0
- for point in pointsDirList:
- # Get normalized values
- norm = (point - pMin) / (pMax - pMin)
- # Assign colors
- vertexColorList[count].r = norm
- vertexColorList[count].g = 0.0
- vertexColorList[count].b = 0.0
- count += 1
- # Sets vert colors
- selMesh.setVertexColors(vertexColorList, vertList)
- print(time.time() - startTime)
Advertisement
Add Comment
Please, Sign In to add comment