I had an error in a code concerning the creation of a mesh animation through fcurves. Solution :
Just replace …
fcurves = [action.fcurves.new(data_path % v.index, i) for i in range(3)]
by
fcurves = [action.fcurves.new(data_path = our_data_path % v.index, index=i) for i in range(3)]
Global code :
def insert_keyframe(fcurves, frame, values):
for fcu, val in zip(fcurves, values):
fcu.keyframe_points.insert(frame, val, options={'FAST'})
obj = bpy.data.objects['trajectory']
mesh = obj.data
action = bpy.data.actions.new("MeshAnimation")
mesh.animation_data_create()
mesh.animation_data.action = action
our_data_path = "vertices[%d].co"
frames = range(1,last_frame+1,1)
for v in mesh.vertices:
fcurves = [action.fcurves.new(data_path = our_data_path % v.index, index=i) for i in range(3)]
for f in frames:
x = tTrajectoire # example of calculation for x, y, z
y = tTrajectoire * tTrajectoire
z = 1/ tTrajectoire
co_kf = [x,y,z]
print("frame : " + str(f) +" | V : "+ str(V) +" | tVals : "+ str(tVals[v.index]) + " | Vertice : "+ str(v.index) + " | localisation " + str(co_kf) )
insert_keyframe(fcurves, f, co_kf)