0
$\begingroup$

I'm trying to do an animation starting from some data I collected. The data is stored in a single txt file which looks like pretty much as

o1 x y t
o1 x y t
...
o2 x y t
...

where o1 and o2 are two object identifiers, x and y are cartesian coordinates on the ground plane, and t is the timestamp of the observations.

My aim is to render the movement of the two objects while preserving time information.

I already know how to read in the text file and create the paths. I'm using this function

def create_curve(coords_list, name):
    crv = bpy.data.curves.new('crv', 'CURVE')
    crv.dimensions = '3D'
    spline = crv.splines.new(type='NURBS')
    spline.points.add(len(coords_list) - 1)
    for p, new_co in zip(spline.points, coords_list):
        p.co = (new_co + [1.0])
    obj = bpy.data.objects.new(f'path_{name}', crv)
    bpy.data.scenes[0].collection.objects.link(obj)

At this point I import the two object models and follow this answer to make them follow the paths.

My problem is that I cannot find an automatic way to link timestamps from the file to the animation keyframes. Is there a way to synchronise the two?

$\endgroup$
2
  • 1
    $\begingroup$ This will be a lot easier if you simply keyframe location values to define the motion path. eg set the location ob1.location = (x, y, 0) and keyframe it ob1.keyframe_insert('location', frame=f(t)) where f converts t to frames. (or build animation fcurve directly from data) $\endgroup$
    – batFINGER
    Aug 12 at 9:30
  • $\begingroup$ thanks for the suggestion @batFINGER, I'll give it a try. My problem though is that I then have to adjust the paths (scale, location) as the data from file is not perfect. By assigning keyframes directly to the objects this is not possible anymore $\endgroup$
    – amelies
    Aug 12 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.