I want to make a specific animation and for this I was thinking in create a mesh and then vary the position of its vertices using a python script, but I don't know how add vertices keyframes on python. Someone can help me?


1 Answer 1


You can keyframe the coordinates of a mesh's vertices similar to how you can keyframe a mesh's location. If 'v' is a vertex of a mesh, you can use v.keyframe_insert("co", frame = some_number) .

This is very similar to how if 'obj' is some object, you can keyframe its location using obj.keyframe_insert("location", frame = some_number)

Here is a great example of a mesh vertex transformation. It's a stereographic projection homeomorphism. First add a sphere to the scene and make sure it's named 'Sphere'. Then go into edit mode, click on the north pole, and delete the north pole. Next, run the following script.

import bpy

sphere = bpy.data.objects["Sphere"]

verts = sphere.data.vertices

# iterate through the vertices of a punctured sphere
for v in verts:
    # keyframe the initial position of each vertex
    v.keyframe_insert("co", frame = 1)
    # store the x, y, and z coordinates into variables x, y, and z
    x = v.co.x
    y = v.co.y
    z = v.co.z
    # change the position of the vertex coordinate based on a stereographic projection function
    v.co = (2*x/(1 - z), 2*y/(1 - z), -1)
    # keyframe the final position of each vertex
    v.keyframe_insert("co", frame = 180)

You must log in to answer this question.

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