Advertisement
Lucas_3D

getGrade

May 22nd, 2021 (edited)
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. grades = #()
  2. --
  3. fn Get2PositionGrade posMin posMax =
  4. (
  5. local vertZMin = posMin.z
  6. local vertZMax = posMax.z
  7. local verticalDistance = vertZMax - vertZMin
  8. local vertXY1 = [posMin.x, posMin.y, 0]
  9. local vertXY2 = [posMax.x, posMax.y, 0]
  10. local horizontalDistance = distance vertXY1 vertXY2
  11. local grade = horizontalDistance / verticalDistance as float
  12. append grades grade
  13. )
  14. fn GradeFace theObj arr =
  15. (
  16. local numberOfPlayers = arr.count
  17. local round = 1
  18. for i = 1 to numberOfPlayers - 1 do
  19. (
  20. for n = (1+round) to numberOfPlayers do
  21. (
  22. if ((polyOp.getVert theObj arr[i]).z < (polyOp.getVert theObj arr[n]).z) then
  23. (
  24. Get2PositionGrade (polyOp.getVert theObj arr[i]) (polyOp.getVert theObj arr[n])
  25. ) else --the argument requires the min and max in that order, so we flip it here.
  26. (
  27. if (polyOp.getVert theObj arr[i]).z > (polyOp.getVert theObj arr[n]).z do
  28. (
  29. Get2PositionGrade (polyOp.getVert theObj arr[n]) (polyOp.getVert theObj arr[i])
  30. )
  31. )
  32. )
  33. round += 1
  34. )
  35. )
  36. fn CalcGrade theObj=
  37. --Send the vert numbers that make up each face to the GradeFace function.
  38. --That pairs up the vert positions and gets the grade using the Get2PositionGrade function.
  39. --An array of grades is populated, it is sorted and the lowest value (which is the steepest grade) is printed.
  40. (
  41. for i = 1 to polyOp.getNumFaces theObj do
  42. (
  43. local faceVerts = polyOp.getFaceVerts theObj i
  44. GradeFace theObj faceVerts
  45. )
  46. if grades.count == 0 then
  47. (
  48. "The object is flat"
  49. ) else
  50. (
  51. steepestGrade = (sort grades)[1]
  52. "The Maximum Grade is: 1:" + steepestGrade as string
  53. )
  54. )
  55. --
  56. if selection.count == 1 and (classof selection[1] == PolyMeshObject or classof selection[1] == Editable_Poly) then
  57. (
  58. CalcGrade selection[1]
  59. ) else
  60. (
  61. "\n****\nInvalid. There needs to be just 1 POLY object selected.\n****\n"
  62. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement