0
$\begingroup$

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!
$\endgroup$
4
  • $\begingroup$ does it work if you try putting a keyword argument, like name="Basis" $\endgroup$
    – pevinkinel
    Oct 3, 2020 at 16:33
  • $\begingroup$ Yeah but after that , I add shapekeys in the loop , but I still do not get the keyframes after running it cdn.discordapp.com/attachments/439399976993292293/… $\endgroup$ Oct 3, 2020 at 16:47
  • $\begingroup$ 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 $\endgroup$
    – pevinkinel
    Oct 3, 2020 at 16:54
  • $\begingroup$ I see , I will look into that $\endgroup$ Oct 3, 2020 at 16:59

1 Answer 1

1
$\begingroup$

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")
$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$
    – Linus
    Jun 25, 2022 at 16:14
  • $\begingroup$ You can use 'foreach_set' directly on the fcurve. Checkout this link: blender.stackexchange.com/questions/111644/… $\endgroup$
    – cgtinker
    Jan 25, 2023 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .