Define motion paths in Blender?

Hi All,



All the motion path examples I’ve seen require the path to be built point-by-point in source code.



Is it possible to define paths as part of my scene in Blender, and construct the motion paths either by iterating through the vertices in the scene paths to build the MotionPath, or somehow just creating a MotionPath automatically by passing it a mesh or path in the scene somehow?



I’ve tried exporting paths and meshes (with only vertex info i.e. lines) from Blender with the Ogre exporter, and while I can get a handle to these objects after loading my scene in JME using rootNode.getChild(“MyPath”), the objects appear to have no vertex information I can inspect.



What am I missing?



Thanks in advance for any help,

Jon.

Just use empty nodes to place the motion path points later along where they are?

Thanks for the response.



Perhaps my question wasn’t expressed very well…



All examples of building MotionPath I’ve seen so far use this method to define the waypoints…

path.addWayPoint(new Vector3f(10, 1.5f, 0));

path.addWayPoint(new Vector3f(10, 1.4f, 10));

etc…



I was wondering if instead of hard-coding all these vectors for each waypoint of a MotionPath, if I could instead just draw a path (or spline, or whatever) visually in Blender, and use the vertex information of the spline to define my MotionPath after importing the scene containing the paths into JME. I’m imagining something like the following (pseudocode)…





aPath = rootNode.getChild(“path1”); // get the geometry of the path

aMotionPath = new MotionPath(); ) // create a MotionPath

for (aVertex in aPath.vertices) { // iterate through the points (somehow)

aMotionPath.addWayPoint( aVertex ); // add a new waypoint for each point in the path (somehow)

}





I guess I’m simply asking: how do you create MotionPaths without having to hard-code a series of waypoints? It’s be nifty if I could define the MotionPath in my blender scene.



Thanks again for your help - it’s very much appreciated.

like I said, ad some marker nodes and use their location:

[java]Spatial markerSpatial = level.getChild("MyMarkerNode1");

path.addWayPoint(markerSpatial.getWorldTranslation);[/java]

(obviously you should automate the name search)

Okay - so a separate empty object in Blender for every waypoint, huh?

You can also try a brain-to-computer interface and just imagine your level…

yeah there is no build in support for path from blender to JME.

What Normen suggest is a good idea though. I don’t thing path are exported at all in the blender exporter, but empties are for sure.

You can also try a brain-to-computer interface and just imagine your level..


Hah, oh how I admire a dry wit. But my killer-game* idea involves moving the camera along a large number of detailed paths; to hand-code or simply whip up a few splines in Blender? Hmm... Thanks for your suggestion though. :)

And thanks nehon... Surely I'm not the only person to have needed to import paths so far!? It might be quicker in the long-run if I write a little python script to export the data I need. I'll let you know how it goes. ;)

THanks guys!

I don’t get whats the issue, you will have to place the markers anyway and doing it in a script file just via coordinates, with no visual feedback, how its that supposed to work? Whats the difference to doing it in code then? Can you name the specific example of what you are trying to do?

I don’t get whats the issue


I would like to have been able to define motion paths by DRAWING them in Blender, over and around the objects in my scene, then upon importing the scene telling JME to "use the points in these splines I've drawn as a camera motion paths!"

Defining individual objects in Blender for waypoints is a workaround (that I"m using right now, thanks!) but it means that i) I can't actually SEE the paths in blender (just the points), ii) I have to manually manage disparate objects (one for every waypoint!) and iii) manually manage the names of the objects to indicate which ones belong to the same path, and their order.

I will investigate the python script solution so that I can scrape my Blender scene for the splines I have drawn, export their vertices to a file, then import into my JME application to be used as the waypoints in motion paths.

As for what I'm trying to achieve, I want a navigation system in which the user clicks on an object/location, and, via a series of *pre-defined* motion paths, moves to that object/location. I will need a lot of (complex) motion paths to navigate from location to location in the environment.

I see. I guess best would be to do it in the SceneComposer, there you could also add a plugin that visualizes the path somehow. Because e.g. terrain you cannot see/edit in blender anyway.

I would do path in blender, export .obj (no material needed, not even faces needed), load it with own loader and setup these vertices.



[java]

Blender v2.61 (sub 0) OBJ File: ‘’

www.blender.org

mtllib path.mtl

o Plane

v -0.347565 0.000000 -2.461765

v -1.000000 0.000000 1.000000

v -1.000000 0.000000 -1.000000

v 0.840120 0.000000 -3.238328

[/java]



[java]

String str=LoadTXT(“test.obj”); // reads whole file to string

String[] lines=str.split(“n”);

for(int line=4;; line++)

{

if(lines[line].charAt(0)==‘f’) break; // if face, leave

String[] val=lines[line].split(" ");

Vertex3f pos=new Vertex3f( parseFloat( val[1]), parseFloat( val[2]), parseFloat( val[3]) ),

path.add(pos);

}

[/java]



Something like that.

Yes! An .obj of course no need for some custom export script! (I was overthinking it. :wink: )



Thanks larda that’s brilliant!

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…



[java]

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()







[/java]

(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)



[java]



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}});



[/java]





:slight_smile:

hello !



Does anyone know how I can retrieve individual splines points rotations from blender like the snipet mentioned ?

I don’t know what kind of blender line to retrieve ? bezier or path ? I tried with bezier and spline.bezier_points but I can’t gain access to rotations



Thanks for helping !



Kine

Hi,



Do you mean the left/right handles on the points of a bezier curve?



There are some examples on this page http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Other_data_types



Look for the script called “curve_types.py”… For a bezier curve, the data you want appears to be accessible by:



curve.splines[n].bezier_points[n].handle_left for the left handle

or .handle_right (right handle)

or .co (the point itself)



Mind you, I’m certainly no expert, so I could be completely wrong!



Hope that helps. :slight_smile:

I’m also encountering a similar problem as the original poster. It would be good to have possibility to import splines to scene. This would make possible creating controls based upon splines and similar stuff.