0

I would like to alternate between a few different objects or meshes to create an animation effect. I, however, would prefer not to animate their render check box, because that is rather inefficient. How could I efficiently animate objects alternating between each other? It would be freaking awesome if I could do it similar to how shape keys work :D Any advice is welcome!

RBlong2us
  • 1,345
  • 10
  • 39

1 Answers1

1

Swap out the meshes.

Using same method outlined here can swap out meshes using a frame change handler.

In example below "Cube" is the object that is having its mesh swapped.

Have made a very simple example by making a mesh name list

["Cube", "Cube", "Cone", "Suzanne"]

use "Cube" on frames 1 and 2, swap to "Cone" on frame 3, then to "Suzanne" on 4 onwards.

Test script, for object named "Cube" use "Cube" mesh for 35 frames, "Cone" next 20 ...

import bpy

def swap_ob_mesh(ob_name, anim):

def handler(scene, depsgraph):
    ob = scene.objects.get(ob_name)
    f = scene.frame_current

    if 0 > f or f  >= len(anim):
        return
    mesh_name = anim[f - 1] # first item on frame 1        
    me = bpy.data.meshes.get(mesh_name)
    if ob and me:
        ob.data = me

return handler

while testing

bpy.app.handlers.frame_change_post.clear()

test call

anim = sum( ( ["Cube"] * 25, ["Cone"] * 20, ["Suzanne"] * 35, ), [] ) bpy.app.handlers.frame_change_post.append( swap_ob_mesh("Cube", anim * 2) )

Improvements:

  • Make a better data set eg "Plane", (22, 44) could indicate to use "Plane" mesh on frames 22 to 44
  • Shapekeys. Make a set of shapekeys on each mesh to emulate a shape of each other mesh. Values could be set to tween at the changes.
batFINGER
  • 84,216
  • 10
  • 108
  • 233