Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- macroScript UE4splineWriter
- category:"Noon"
- toolTip:"UE4 Spline Writer"
- buttonText:"UE4 Spline Writer"
- Icon:#("Splines", 1)
- /*
- @AlanNoon
- 12.13.16
- CURRENT LIMITATIONS:
- Only works with one subspline per spline shape, as UE4 requires "Allow Discontinuous Spline" to be set manually on a spline component.
- Once this can be scripted via BP, go back and add support for exporting multiple subsplines.
- */
- (
- fn SplineWriter =
- (
- try
- (
- vertPosArray = #()
- vertInArray = #()
- vertOutArray = #()
- -- setUserPropBuffer $ ""
- csvFileName = getSaveFileName caption: "Save Spline Data" types:"CSV(*.csv)|*.csv|"
- csvFile = createFile csvFileName
- -- openFile csvFile
- theSpline = convertToSplineShape $
- theSpline = $
- numPoints = numKnots theSpline 1
- print numPoints
- -------------
- --Determine if Spline is closed or not
- -------------
- -------------
- --Read the knots
- -------------
- for v = 1 to (numKnots theSpline 1) do
- (
- vertPos = in coordsys world getKnotPoint theSpline 1 v --as string
- vertPos = (vertPos * [1,-1,1])
- append vertPosArray vertPos
- )
- for v = 1 to (numKnots theSpline 1) do
- (
- vertIn = in coordsys world getInVec theSpline 1 v
- append vertInArray vertIn
- )
- for v = 1 to (numKnots theSpline 1) do
- (
- vertOut = in coordsys world getOutVec theSpline 1 v
- append vertOutArray vertOut
- )
- -------------
- --Format the knot data
- -------------
- theString = stringstream ""
- format ",XPos,YPos,ZPos,XInTangent,YInTangent,ZInTangent,XOutTangent,YOutTangent,ZOutTangent\r\n" to:theString
- for i = 1 to numPoints do
- (
- format ("vert" + (i - 1) as string + ",") to: theString
- format (vertPosArray[i][1] as string + "," + vertPosArray[i][2] as string + "," + vertPosArray[i][3] as string ) to: theString
- format "," to:theString
- 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
- format "," to:theString
- 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
- format "\r\n" to:theString
- )
- --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.
- --IIRC: UE4 creates a dupe point at the end of a closed spline.
- --The Spline Importer Blueprint will have to set the spline to closed, and then NOT create an additional point as UE4 will do this
- --automatically, but WILL have to set the tangent handles to make end points match.
- if isOpen = isClosed $ 1 do
- (
- format ("vert" + (numPoints) as string + ",") to: theString
- format (vertPosArray[1][1] as string + "," + vertPosArray[1][2] as string + "," + vertPosArray[1][3] as string ) to: theString
- format "," to:theString
- format (vertInArray[1][1] as string + "," + (-1 * vertInArray[1][2]) as string + "," + (-1 * vertInArray[1][3]) as string ) to: theString
- format "," to:theString
- format (vertOutArray[1][1] as string + "," + (-1 * vertOutArray[1][2]) as string + "," + (-1 * vertOutArray[1][3]) as string ) to: theString
- format "\r\n" to:theString
- )
- /*
- --writes data to use prop buffer for quick debugging while testing this tool
- setUserPropBuffer theSpline theString
- */
- format (theString as string) to:csvFile
- close csvFile
- free csvFile
- )
- catch
- (
- print "Error writing spline data."
- )
- )
- rollout UE4splineWriterRollout "Spline Export Tool"
- (
- label lbl_inst0 ""
- label lbl_inst1 "Select Spline Shape"
- label lbl_inst2 ""
- button btn_writeSpline "Export Spline Data" tooltip: "Exports Spline Data to File"
- on btn_writeSpline pressed do
- (
- print $
- SplineWriter()
- )
- )
- if UE4splineWriterFloater != undefined then closeRolloutFloater UE4splineWriterFloater
- UE4splineWriterFloater = newRolloutFloater "UE4 Spline Writer" 260 120 --70 130
- addRollout UE4splineWriterRollout UE4splineWriterFloater
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement