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?
ob1.location = (x, y, 0)and keyframe itob1.keyframe_insert('location', frame=f(t))wherefconvertstto frames. (or build animation fcurve directly from data) – batFINGER Aug 12 '21 at 09:30