Advertisement
Guest User

MaxScript

a guest
Jan 22nd, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1.  
  2. macroScript UE4splineWriter
  3. category:"Noon"
  4. toolTip:"UE4 Spline Writer"
  5. buttonText:"UE4 Spline Writer"
  6. Icon:#("Splines", 1)
  7.  
  8.  
  9. /*
  10. @AlanNoon
  11.  
  12. 12.13.16
  13.  
  14. CURRENT LIMITATIONS:
  15. Only works with one subspline per spline shape, as UE4 requires "Allow Discontinuous Spline" to be set manually on a spline component.
  16. Once this can be scripted via BP, go back and add support for exporting multiple subsplines.
  17.  
  18.  
  19.  
  20. */
  21. (
  22. fn SplineWriter =
  23. (
  24. try
  25. (
  26. vertPosArray = #()
  27. vertInArray = #()
  28. vertOutArray = #()
  29.  
  30. -- setUserPropBuffer $ ""
  31. csvFileName = getSaveFileName caption: "Save Spline Data" types:"CSV(*.csv)|*.csv|"
  32. csvFile = createFile csvFileName
  33. -- openFile csvFile
  34. theSpline = convertToSplineShape $
  35.  
  36. theSpline = $
  37. numPoints = numKnots theSpline 1
  38. print numPoints
  39.  
  40. -------------
  41. --Determine if Spline is closed or not
  42. -------------
  43.  
  44.  
  45.  
  46. -------------
  47. --Read the knots
  48. -------------
  49.  
  50. for v = 1 to (numKnots theSpline 1) do
  51. (
  52. vertPos = in coordsys world getKnotPoint theSpline 1 v --as string
  53. vertPos = (vertPos * [1,-1,1])
  54. append vertPosArray vertPos
  55. )
  56. for v = 1 to (numKnots theSpline 1) do
  57. (
  58. vertIn = in coordsys world getInVec theSpline 1 v
  59. append vertInArray vertIn
  60. )
  61. for v = 1 to (numKnots theSpline 1) do
  62. (
  63. vertOut = in coordsys world getOutVec theSpline 1 v
  64. append vertOutArray vertOut
  65. )
  66.  
  67. -------------
  68. --Format the knot data
  69. -------------
  70.  
  71. theString = stringstream ""
  72.  
  73. format ",XPos,YPos,ZPos,XInTangent,YInTangent,ZInTangent,XOutTangent,YOutTangent,ZOutTangent\r\n" to:theString
  74. for i = 1 to numPoints do
  75. (
  76. format ("vert" + (i - 1) as string + ",") to: theString
  77. format (vertPosArray[i][1] as string + "," + vertPosArray[i][2] as string + "," + vertPosArray[i][3] as string ) to: theString
  78. format "," to:theString
  79. format (vertInArray[i][1] as string + "," + (-1 * vertInArray[i][2]) as string + "," + vertInArray[i][3] as string ) to: theString --negate the Y component to account for Y Axis differences from 3dsmax to UE4. Multiply by 3 to convert from bezier to hermite
  80. format "," to:theString
  81. format (vertOutArray[i][1] as string + "," + (-1 * vertOutArray[i][2]) as string + "," + vertOutArray[i][3] as string ) to: theString --negate the Y component to account for Y Axis differences from 3dsmax to UE4 Multiply by 3 to convert from bezier to hermite
  82. format "\r\n" to:theString
  83. )
  84.  
  85. --if shape is closed, add an additional point at the end of the CSV matching the first to account for how UE4 handles closed splines.
  86. --IIRC: UE4 creates a dupe point at the end of a closed spline.
  87. --The Spline Importer Blueprint will have to set the spline to closed, and then NOT create an additional point as UE4 will do this
  88. --automatically, but WILL have to set the tangent handles to make end points match.
  89.  
  90.  
  91. if isOpen = isClosed $ 1 do
  92. (
  93. format ("vert" + (numPoints) as string + ",") to: theString
  94. format (vertPosArray[1][1] as string + "," + vertPosArray[1][2] as string + "," + vertPosArray[1][3] as string ) to: theString
  95. format "," to:theString
  96. format (vertInArray[1][1] as string + "," + (-1 * vertInArray[1][2]) as string + "," + (-1 * vertInArray[1][3]) as string ) to: theString
  97. format "," to:theString
  98. format (vertOutArray[1][1] as string + "," + (-1 * vertOutArray[1][2]) as string + "," + (-1 * vertOutArray[1][3]) as string ) to: theString
  99. format "\r\n" to:theString
  100. )
  101.  
  102.  
  103.  
  104. /*
  105. --writes data to use prop buffer for quick debugging while testing this tool
  106. setUserPropBuffer theSpline theString
  107. */
  108. format (theString as string) to:csvFile
  109.  
  110. close csvFile
  111. free csvFile
  112. )
  113. catch
  114. (
  115. print "Error writing spline data."
  116. )
  117. )
  118.  
  119. rollout UE4splineWriterRollout "Spline Export Tool"
  120. (
  121.  
  122. label lbl_inst0 ""
  123. label lbl_inst1 "Select Spline Shape"
  124. label lbl_inst2 ""
  125. button btn_writeSpline "Export Spline Data" tooltip: "Exports Spline Data to File"
  126.  
  127. on btn_writeSpline pressed do
  128. (
  129. print $
  130. SplineWriter()
  131. )
  132. )
  133.  
  134. if UE4splineWriterFloater != undefined then closeRolloutFloater UE4splineWriterFloater
  135.  
  136. UE4splineWriterFloater = newRolloutFloater "UE4 Spline Writer" 260 120 --70 130
  137. addRollout UE4splineWriterRollout UE4splineWriterFloater
  138. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement