0

The code without adding the keyframe

>>> c=bpy.data.objects["Z Function"]
>>> for f in range(100):
...     bpy.context.scene.frame_set(f)
...     for v in c.data.vertices:
...         v.co.z=np.sin((np.pi*f)*(v.co.x))+np.cos((np.pi*f)*(v.co.y))
...     # add keyframe for mesh vertice here 

I tried using ob.keyframe_insert(data_path="location",index=-1) but didnt work because it probably keyframes the objects location and not the vertex's

I read this thread and it looked a bit complex to me , is there no solution to keyframing mesh vertex without using fcurves ?

Another thread used shapekeys to deform , but when I try add shape keys I get the following error enter image description here

>>> sk_basis = c.shape_key_add("Basis")
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: Object.shape_key_add(): required parameter "name" to be a keyword argument!
  • does it work if you try putting a keyword argument, like name="Basis" – pevinkinel Oct 03 '20 at 16:33
  • Yeah but after that , I add shapekeys in the loop , but I still do not get the keyframes after running it https://cdn.discordapp.com/attachments/439399976993292293/761992456350728233/blenderprob.gif – soutrik das Oct 03 '20 at 16:47
  • right, i think you know way more than i do :) the problem might be that the only thing you can keyframe is a shapekey's influence, not the shapekey itself – pevinkinel Oct 03 '20 at 16:54
  • I see , I will look into that – soutrik das Oct 03 '20 at 16:59

1 Answers1

1

Vertices can be keyframed using the method keyframe_insert - pass the vertices you want to keyframe at a given frame in the function below.

def keyframe(vert, frame):
    for index in range(3):    
        vert.keyframe_insert("co", index=index, frame=frame, group="location")
Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
cgtinker
  • 31
  • 2
  • Do you know if there's a way to do this without looping in python? It gets very slow with a large number of vertices – Linus Jun 25 '22 at 16:14
  • You can use 'foreach_set' directly on the fcurve. Checkout this link: https://blender.stackexchange.com/questions/111644/fast-keyframe-insertion – cgtinker Jan 25 '23 at 15:57