0
$\begingroup$

I am animating the vibrations on a mesh by moving the nodes through a series of positions. I have a small preliminary code for a few locations. I need to animate each location of each node with a frame. I have this not very robust code for a preliminary test. When I try to run it, the application stops responding. How do I improve the code?

frame_start = bpy.context.scene.frame_start
frame_end = 4

new_position = [(0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0)]

while True :
    frame = frame_start
    
    while frame <= frame_end:

        for j, vertex in enumerate(mesh.vertices):
            for i, node in enumerate(new_position):
               
                original_positions = [vertex.co.copy() for vertex in mesh.vertices]
                mesh.vertices[j].select = True
           
                bpy.ops.object.mode_set(mode='EDIT')

                bpy.ops.transform.translate(value=node)
               
                bpy.ops.object.mode_set(mode='OBJECT')
                              
                mesh.update()
                mesh.vertices[j].keyframe_insert(data_path='co', frame=frame)``` 
            

$\endgroup$
1
  • 2
    $\begingroup$ application stops responding because your code is stuck in infinite loop. you never incremented frame so while frame <= frame_end is always True. Use range() or increment frame. Also there is no break condition of outer while loop. $\endgroup$
    – JayReigns
    Commented Oct 16, 2023 at 15:06

0

You must log in to answer this question.

Browse other questions tagged .