Hi Commmon,
I figured out a pretty consistent way to import splines into unity from blender, but it’s not free. It’s really convoluted, but ultimately pretty easy once you get it set up. I’m going to provide a detailed explanation assuming no knowledge of anything at all in case someone like me stumbles across this (other than assuming you already have a bezier curve in blender to work with).
First, you need dreamteck splines. It’s on sale right now for about $18, usually its $35. Dreamteck can import splines into unity.
Once you buy this plugin, go to the project manager window in unity, import it, and then import the examples (by clicking on Examples in the Dreamteck/Splines folder). I needed a rollercoaster example so I used that one to figure out how to convert my coaster into a working spline. I know Dreamteck has built in tube functionality as well, so it might be worth checking out if you’re still on the same project. Here is the documentation:
The problem is that dreamteck splines only imports SVG and CSV files. Blender doesn’t natively export to either of those formats. This is where the convoluted part comes in.
https://blender.stackexchange.com/questions/51706/exporting-coordinates-of-vertices-to-csv
This thread can get you started with exporting to CSV from blender. I had to make some changes to the script they used, so here is my version (formatting might be a little weird on this forum).
import bpy
outputFile = 'C:/Users/Work/Desktop/YourFolder/spline.csv'
verts = [ bpy.context.object.matrix_world @ v.co for v in bpy.context.object.data.vertices ]
csvLines = [ ";".join([ str(v) for v in co ]) + "\n" for co in verts ]
f = open( outputFile, 'w' )
f.writelines( csvLines )
f.close()
You have to change the “*” sign that they originally used in line 3 to an “@” sign for newer versions of blender. You also have to make sure that the slashes are forward slashes when copying your folder address. Make sure it’s exporting to a folder you actually want!
In order to use this, make a copy of your spline with shift + d, then use F3-> Convert To → Convert To Mesh From Bezier Curve.
Next, go to the scripting tab in blender. Copy the code into the Text Editor in the middle, and do Text->Save As somewhere useful. Make sure your curve mesh is selected. Then, click Run Script.
This is where it really gets convoluted. This script places all the coordinate data into one column in the CSV file, but Dreamteck needs each coordinate data point (x,y,z) to have it’s own column. I don’t know enough about python to fix this, but there is an easy enough workaround.
You can open the CSV file in Microsoft Excel, then click on the “A” column to select everything, go to Data-> From Table, and just hit enter. When the new window pops up, click on Split Column → By Delimiter → set the Delimiter to semicolon or type “;”. Then, hit close and load. This should split the data into 3 columns.
Next, scroll down to the bottom, and make sure all the data points are visible. Drag the “…” thing down if they aren’t.
Finally, save the file. It will give you a warning, just hit yes. Close the file, and reopen the file. Right click on Row 1 (with the titles) and delete. Save the file again. Close the file.
Finally, go back to unity. Import the CVS file into a unity folder by just dragging it in. You can change the name to something useful here.
In unity, click on Window → Dreamteck → Splines → Tool. Go to import/export, and import your spline. You have to change the import options to only use position (this is why we converted the data specifically to three columns). You may need to adjust the axis (and change the scale to -1). If you also have a corresponding (visible) mesh, you can place that in the scene as well, and make your spline a child of the mesh, then set the spline space to local in the Spline Computer component. You probably also want to set the type to B Spline, and fix the normals (if someone knows how to export normal data/ coordinate data straight from a Bezier curve into a CVS file please comment). You should now be able to move your spline around and reposition it.
To get it working and test it, just replace the spline in the example with you new spline.
Hope this is useful if anyone stumbles across this!
Nick