For what it’s worth, I ran into trouble with the .obj export as well, so invested a bit of time with the python script.
The following addon script exports selected paths in Blender as java source code which can be copy-pasted directly into my class, but could easily be customised if anyone else would benefit from such a thing…
bl_info = {
"name": "export paths 1.0",
"author": "Tai Po",
"version": (0, 1, 0),
"blender": (2, 5, 9),
"api": 37702,
"location": "File > Export > Export Path Data",
"description": "Export points in paths",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
import os
import bpy
import io
import mathutils
from math import radians
from bpy.props import StringProperty, EnumProperty, BoolProperty
class TestExporter(bpy.types.Operator):
bl_idname = "export.test"
bl_label = "Export Paths"
filepath = StringProperty(subtype='FILE_PATH')
# This is called first. It will open the file selector; after the user
# selected a file, execute(self,context) is called.
def invoke(self, context, event):
if not self.filepath:
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".txt")
WindowManager = context.window_manager
WindowManager.fileselect_add(self)
return {"RUNNING_MODAL"}
# Called by the file selector
def execute(self, context):
filepath = self.filepath
self.save(context, **self.properties)
return {"FINISHED"}
# Save the file
def save(self, context, filepath=""):
if os.path.splitext(filepath)[1] == '':
filepath += ".txt"
f = io.open(filepath, mode="wt", newline="n", encoding="utf_8")
obs = bpy.context.selected_objects
for ob in obs:
f.write("thePaths.put("%s"," % (ob.name));
wmt = ob.matrix_world
splines = ob.data.splines
f.write("new float[][]{");
for spline in splines:
lastindex = len(spline.points)-1
for index, pt in enumerate(spline.points):
co = pt.co * wmt
f.write("{%ff,%ff,%ff}" % (co.x,co.z,-co.y));
if not(index == lastindex):
f.write(",")
f.write("}");
f.write(");n");
f.close()
def menu_func(self, context):
self.layout.operator(TestExporter.bl_idname, text="Export Template (for test)")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_func)
if __name__ == "__main__":
register()
(NB: Blender uses a different coordinate system to JME, so you have to swap the Y & Z axes, and make the Z value negative.)
… and here’s an example of the output (I’m using custom PathManager and PathDef objects to build & manage the MotionPaths)
thePaths.put("Path2",new float[][]{{0.552299f,-3.205562f,0.000000f},{1.772858f,-2.669704f,-0.456506f},{2.050186f,-0.636155f,-0.963735f},{4.234775f,-0.129691f,-0.456506f},{4.682837f,2.490573f,0.000001f}});
thePaths.put("Path1",new float[][]{{-2.922342f,3.740610f,-0.000000f},{-1.691757f,3.228198f,-0.456506f},{-0.029767f,4.432367f,-0.963735f},{1.845480f,3.202577f,-0.456506f},{4.049649f,4.688573f,0.000000f}});
thePaths.put("Path3",new float[][]{{-4.455926f,2.620504f,-0.000000f},{-4.434050f,1.287676f,-0.456507f},{-2.666182f,0.245144f,-0.963736f},{-3.044405f,-1.965259f,-0.456507f},{-0.801575f,-3.392234f,-0.000000f}});