avoorhees

Maya vert colors

May 3rd, 2017
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import maya.api.OpenMaya as om2
  2. import time
  3.  
  4. startTime = time.time()
  5.  
  6. # API get the mesh
  7. selList = om2.MGlobal.getActiveSelectionList()
  8. dagPath = selList.getDagPath(0)
  9. selMesh = om2.MFnMesh(dagPath)
  10.  
  11. # Get vert list
  12. vertList = list(set(selMesh.getVertices()[1]))
  13. lenVertList = len(vertList)
  14.  
  15. # Initial color info
  16. tempColor = om2.MColor([0.0,0.0,0.0])
  17. vertexColorList = om2.MColorArray(lenVertList, tempColor)
  18.  
  19. # Get points and values
  20. pointsList = selMesh.getPoints(om2.MSpace.kWorld)
  21. pointsDirList = ([p[1] for p in pointsList])
  22. pMin = min(pointsDirList)
  23. pMax = max(pointsDirList)
  24.  
  25. count = 0
  26. for point in pointsDirList:
  27.     # Get normalized values
  28.     norm = (point - pMin) / (pMax - pMin)
  29.    
  30.     # Assign colors
  31.     vertexColorList[count].r = norm
  32.     vertexColorList[count].g = 0.0
  33.     vertexColorList[count].b = 0.0
  34.     count += 1
  35.  
  36. # Sets vert colors
  37. selMesh.setVertexColors(vertexColorList, vertList)
  38.  
  39. print(time.time() - startTime)
Advertisement
Add Comment
Please, Sign In to add comment