Anybody know how to create a spline path from an object's motion?

My google skills are really failing me here. I just want to make a spline path from an object’s keyframed motion. I see I can compute a motion path to display it in the viewport. Any way I can save that path as a spline? Any other way to save the object’s motion path as a spline? Addon? Script? Anything?

Not sure what your ultimate goal is, but have you check out Motion Trails?
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Animation/Motion_Trail

Matt,

Here is a short script that takes an animated object and creates a curve out of the animation path. Select your object and run the script. You will get a new curve in the scene. The passes variable controls the density of the points created in the final curve. This is a sampling technique.

NOTE: The last point in the curve ends up at world origin (bug…sorry) so put the curve in edit mode and delete that last point. Also if you are creating multiple curves from multiple animated sources you will have to generate them one at a time and rename both the Object and the Datablock after generation to preserve your work. This is because the naming in this simple script is hard coded and it will attempt to reuse the curve datablock if it exists in memory, including the curve you just generated. So if your curve suddenly changes into another curve after you run it for the second time that is why. Rename both parts of the object to lock it in.


# Animation Path To Curve Object.
# Atom 2014
import bpy

passes = 3                                      # Frame end divided by this number equals final curve point count. (Higher = Low Res, Low = More Points)
scene = bpy.data.scenes[0]
ob = bpy.context.active_object

myCurveOBName = "curve_from_animation"          # New curve will have this name.
myCurveName = "cu_curve_datablock"              # New curve datablock will have this name.
cu_tracer = bpy.data.curves.get(myCurveName)
if cu_tracer == None:
    # Create a new curve.
    cu_tracer = bpy.data.curves.new(myCurveName,'CURVE')
else:
    #Reuse this existing curve, but we must remove all of the current splines.
    for old_spline in cu_tracer.splines:
        try:
            cu_tracer.splines.remove(old_spline)
        except:
            print("ERROR: Trying to remove old_spline")


cu_tracer.dimensions = '3D'              
spline = cu_tracer.splines.new('BEZIER')                                           
spline.bezier_points.add(scene.frame_end//passes)                                   # Pre-create the number of points in this spline based upon passes value.


ob_particle_path = bpy.data.objects.get(myCurveOBName)
if ob_particle_path == None:
    try:    
        ob_particle_path = bpy.data.objects.new(myCurveOBName,cu_tracer)            # Create a new curve type object.
        scene.objects.link(ob_particle_path)                                        # Link it to the scene.
    except:
        print("ERROR: Failed to create [" + particle_curve_name + "].")
else:
    print("WARNING: [" + particle_curve_name + "] already exists.") 

# Populate the empty spline with points along the path by scanning time.
for t in list(range(int(scene.frame_end))):
    scene.frame_set(t)
    if not t%passes:
        p = spline.bezier_points[t//passes]
        p.handle_right_type='AUTO'
        p.handle_left_type='AUTO'
        p.co = ob.location
        p.tilt = 0.0
        p.radius = 0.0

Attachments

27_animation_to_curve.blend (91.6 KB)

Does the Motion Trail addon let you extract a separate spline from a Motion Trail? Don’t know…

Found this (ancient) thread, haven’t tried it out though. Maybe helpful:

http://blenderartists.org/forum/archive/index.php/t-202878.html

Or the hard way:
Might be a bit tedious, but you could add a spline and then go from keyframe to keyframe. At each keyframe you put ‘Cursor to Object’ (Shift S), select the spline, go to Edit mode, select the next vertex, ‘Selection to Cursor’.
Certainly a bummer with a long animation…

Interesting. If I could freeze the motion path, that would be great. Doesn’t seem I can though.

What I am ultimately trying to do is display a renderable motion path. The animation is done. Now I simply want to convert the motion to a spline.

BOOM Atom! That is exactly what I needed! Have you considered making this an addon? Genius. Perfect.

I just made it up today. I thought the bTrace tools already did this but when I tried them out, I found that the bTrace tools traces along edges, not animation. It kind of makes sense to be added to that tool, however. Trace animation. I know Liero has a similar AddOn that will create real curves out of particle paths too.

Hi Atom,

i get an error in the infobar which says check console, but i dont see any thing???

EDIT
it works fine in 2.70 i just noticed