Edwarddv

Face Weighted Normals Maxscript

Dec 20th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. addModifier $ (Edit_Normals ()) ui:on
  3.  
  4. numNorms = $.Edit_Normals.GetNumNormals()
  5. numFaces = $.Edit_Normals.GetNumFaces()
  6.  
  7. normalArray = #() --place to store temp info for each normal.
  8.  
  9. --fill in normalArray with junk data.
  10. for i = 1 to numNorms do
  11. (
  12. append normalArray [0,0,0]
  13. )
  14.  
  15. -- iterate through all the faces in the mesh. find out which normals belond to this face and then add the weighted value of the face normal to value already in normalArray
  16. for i = 1 to numFaces do
  17. (
  18. curFace = #{i}
  19.  
  20. connectedNormals = #{}
  21. $.Edit_Normals.ConvertFaceSelection curFace connectedNormals --should now have a bit array of normals connected to current face.
  22. faceNormal = ( in coordsys local polyop.getFaceNormal $ i) * (polyop.getFaceArea $ i) --getweighted normal for current face.
  23. for j in connectedNormals do
  24. (
  25.  
  26. normalArray[j] = normalArray[j]+faceNormal --add current face value to it.
  27.  
  28. )
  29.  
  30.  
  31. )
  32.  
  33. --normalize values in normaArray and apply to mesh.
  34. for i = 1 to numNorms do
  35. (
  36. $.Edit_Normals.SetNormalExplicit i
  37. normalArray[i] = normalize normalArray[i]
  38. in coordsys local $.Edit_Normals.SetNormal i normalArray[i]
  39. )
Add Comment
Please, Sign In to add comment