Skip to content

Instantly share code, notes, and snippets.

@drewp
Created September 9, 2024 23:36
Show Gist options
  • Select an option

  • Save drewp/ecae8d22f9461a7072d4dc79fd91b10f to your computer and use it in GitHub Desktop.

Select an option

Save drewp/ecae8d22f9461a7072d4dc79fd91b10f to your computer and use it in GitHub Desktop.
bl_info = {"name": "Zoetrope", "category": "Animation"}
import bpy
class Zoetrope(bpy.types.Operator):
bl_idname = "anim.zoetrope"
bl_label = "Zoetrope"
def execute(self, context):
scene = context.scene
anim_col = self.get_or_create_coll("anim")
src_objs = bpy.context.selected_objects
scene.frame_set(0)
for i in range(scene.frame_start, scene.frame_end + 1):
scene.frame_set(i)
bpy.ops.object.select_all(action='DESELECT')
for obj in src_objs:
obj.select_set(True)
bpy.ops.object.duplicate()
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
for j, copy_obj in enumerate(bpy.context.selected_objects):
copy_obj.name = f"frame.{i}.{j}"
self.apply_armature(copy_obj)
self.move_to_collection(anim_col, copy_obj)
return {'FINISHED'}
def move_to_collection(self, anim_col, obj):
for col in obj.users_collection:
col.objects.unlink(obj)
anim_col.objects.link(obj)
def apply_armature(self, obj):
for mod in obj.modifiers:
if mod.type == 'ARMATURE':
bpy.ops.object.modifier_apply(modifier=mod.name, use_selected_objects=True)
def get_or_create_coll(self, name: str):
if name not in [col.name for col in bpy.data.collections]:
bpy.data.collections.new(name)
anim_col = bpy.data.collections[name]
return anim_col
def register():
bpy.utils.register_class(Zoetrope)
def unregister():
bpy.utils.unregister_class(Zoetrope)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment