Advertisement
Lucas_3D

Untitled

Jan 25th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. plugin simpleObject helperSample
  2. name:"HelperSample"
  3. category:"HowTo"
  4. classID:#(0x453e608, 0x40dda998)
  5. (
  6. parameters main rollout:params
  7. (
  8. p1 type:#maxObject
  9. p2 type:#maxObject
  10. p3 type:#maxObject
  11. stairWidth type:#worldUnits ui:spnStairWidth default:5.0
  12. )
  13. rollout params "Parameters"
  14. (
  15. spinner spnStairWidth "Stair Width" range:[-100.0,100.0,5.0] type:#worldunits
  16. --
  17. on spnStairWidth changed theVal do
  18. (
  19. p2UnitVector = p2.node.transform[1]
  20. rotatedMatrix = rotateZMatrix 90
  21. rotatedVector = p2UnitVector * rotatedMatrix
  22. p3.node.pos = p2.node.pos + (rotatedVector * this.stairWidth)
  23. )
  24. )
  25. fn isValid= isValidObj p1 and isValidObj p2 and isValidObj p3
  26. fn rot=
  27. (
  28. p2Vec = [p1.node.pos.x, p1.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0]
  29. p2Angle = atan2 p2Vec.y p2Vec.x
  30. p2Matrix = rotate (matrix3 1) (eulerangles 0.0 0.0 p2Angle as quat)
  31. scale p2Matrix p2.node.scale
  32. translate p2Matrix p2.node.pos
  33. p2.node.transform = p2Matrix
  34. p3Vec = [p2.node.pos.x, p2.node.pos.y, 0] - [p3.node.pos.x, p3.node.pos.y, 0]
  35. p3Angle = atan2 p3Vec.y p3Vec.x
  36. p3Matrix = rotate (matrix3 1) (eulerangles 0.0 0.0 p3Angle as quat)
  37. scale p3Matrix p3.node.scale
  38. translate p3Matrix p3.node.pos
  39. p3.node.transform = p3Matrix
  40. )
  41. on load do when transform #(p1, p2, p3) changes id:#forceUpdate do notifyDependents this
  42. on buildMesh do if isValid() do
  43. (
  44. /*when p1 moves the build is not taking it's position into account...*/
  45. local owner = refs.dependentNodes this firstOnly:on
  46. lDir = [p2.node.pos.x, p2.node.pos.y, 0] - [p1.node.pos.x, p1.node.pos.y, 0]
  47. lUVec = normalize lDir
  48. wDir = [p3.node.pos.x, p3.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0]
  49. wUVec = normalize wDir
  50. totalStairLength = distance [p1.node.pos.x,p1.node.pos.y] [p2.node.pos.x,p2.node.pos.y]
  51. amountOfStairs = (totalStairLength / 1) as integer
  52. stepLength = 1
  53. totalStairDrop = p2.node.pos.z - p1.node.pos.z
  54. dropDist = totalStairDrop / amountOfStairs
  55. stepWidth = distance [p2.node.pos.x,p2.node.pos.y] [p3.node.pos.x,p3.node.pos.y]
  56. fn stairVec _pnt3=
  57. (
  58. local lDir = [p2.node.pos.x, p2.node.pos.y, 0] - [p1.node.pos.x, p1.node.pos.y, 0]
  59. local lUVec = normalize lDir
  60. local wDir = [p3.node.pos.x, p3.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0]
  61. local wUVec = normalize wDir
  62. local x = wUVec * _pnt3[1] --width
  63. local y = lUVec * _pnt3[2]--length
  64. local z = _pnt3[3] --drop
  65. return (x + y + [0,0,z])
  66. )
  67. vert_array =#()
  68. face_array =#()
  69. vert_count = 0
  70. vertPos = undefined
  71. for i = 1 to amountOfStairs do
  72. (
  73. if i == 1 then
  74. (
  75. --6 verts
  76. vertPos = [0,0,0]
  77. append vert_array vertPos
  78. append vert_array (vertPos + (stairVec [stepWidth,0,0]))
  79. append vert_array (vertPos + (stairVec [stepWidth,stepLength,0]))
  80. append vert_array (vertPos + (stairVec [0,stepLength,0]))
  81. append vert_array (vertPos + (stairVec [stepWidth,stepLength,dropDist]))
  82. append vert_array (vertPos + (stairVec [0,stepLength,dropDist]))
  83. --4 faces
  84. append face_array [vert_count+1, vert_count+2, vert_count+3]
  85. append face_array [vert_count+1, vert_count+3, vert_count+4]
  86. append face_array [vert_count+4, vert_count+3, vert_count+5]
  87. append face_array [vert_count+4, vert_count+5, vert_count+6]
  88. vert_count += 6
  89. ) else
  90. (
  91. --4 verts
  92. append vert_array (vertPos + (stairVec [stepWidth,stepLength,0]))
  93. append vert_array (vertPos + (stairVec [0,stepLength,0]))
  94. append vert_array (vertPos + (stairVec [stepWidth,stepLength,dropDist]))
  95. append vert_array (vertPos + (stairVec [0,stepLength,dropDist]))
  96. --4 faces
  97. append face_array [vert_count,vert_count-1,vert_count+1]
  98. append face_array [vert_count,vert_count+1,vert_count+2]
  99. append face_array [vert_count+2,vert_count+3,vert_count+4]
  100. append face_array [vert_count+2,vert_count+1,vert_count+3]
  101. vert_count += 4
  102. )
  103. vertPos = vert_array[vert_array.count]
  104. )
  105. setMesh mesh verts:vert_array faces:face_array smGroup:0
  106. for i = 1 to (getNumFaces mesh) do
  107. (
  108. setFaceSmoothGroup mesh i 0
  109. )
  110.  
  111. )--end buildMesh
  112. tool create numPoints:2
  113. (
  114. local p3Pos
  115. on mousePoint click do if click == 1 do
  116. (
  117. p3Pos = undefined
  118. nodeTM.translation = gridPoint
  119. local owner = refs.dependentNodes this firstOnly:on
  120. print (refs.dependentNodes this firstOnly:on)
  121. p1 = NodeTransformMonitor node:(Point prefix:"p1-" parent:owner showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow)
  122. p2 = NodeTransformMonitor node:(Point prefix:"p2-" parent:p1.node showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow)
  123. p3 = NodeTransformMonitor node:(Point prefix:"p3-" parent:p2.node showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow)
  124. p1.node.pos = owner.position
  125. when transform #(p1, p2, p3) changes id:#forceUpdate do notifyDependents this
  126. when transform #(p2, p3) changes id:#stairsPointDirection do rot()
  127. )
  128. on mouseMove click do if click == 2 and lbutton do
  129. (
  130. p2.node.pos = worldPoint
  131. p2UnitVector = p2.node.transform[1]
  132. rotatedMatrix = rotateZMatrix 90
  133. rotatedVector = p2UnitVector * rotatedMatrix
  134. p3.node.pos = p2.node.pos + (rotatedVector * this.stairWidth)
  135. )
  136. )
  137. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement