import bpy from bpy.props import IntProperty from bpy.types import Operator from . import core class ANIM_OT_stepped_bake(Operator): bl_description = "Sample the interpolated animation every N frames and replace it with constant keys" bl_idname = "anim.stepped_bake" bl_label = "Make Stepped" bl_options = {'REGISTER', 'UNDO'} step: IntProperty( name="Step", description="Frames to hold each pose (0 = use the panel setting)", default=0, min=0, soft_max=24, ) @classmethod def poll(cls, context): return context.scene is not None and ( context.selected_objects or context.active_object) def execute(self, context): settings = context.scene.stepped_anim step = self.step or core.effective_step(settings) if settings.range_mode == 'CUSTOM' and settings.frame_end < settings.frame_start: self.report({'ERROR'}, "Custom range end is before its start") return {'CANCELLED'} curves, actions = core.bake_stepped(context, settings, step) if curves == 0: self.report({'WARNING'}, "No animated channels found on the selection") return {'CANCELLED'} self.report({'INFO'}, f"Stepped {curves} curve(s) in {actions} action(s) on {step}s") return {'FINISHED'} class ANIM_OT_stepped_restore(Operator): bl_description = "Restore the smooth animation saved before the last stepped bake" bl_idname = "anim.stepped_restore" bl_label = "Restore Smooth" bl_options = {'REGISTER', 'UNDO'} @classmethod def poll(cls, context): return context.scene is not None and core.has_backup( context, context.scene.stepped_anim.include_data) def execute(self, context): count = core.restore_backups(context, context.scene.stepped_anim.include_data) if count == 0: self.report({'WARNING'}, "No smooth backups found on the selection") return {'CANCELLED'} self.report({'INFO'}, f"Restored smooth animation on {count} datablock(s)") return {'FINISHED'} classes = (ANIM_OT_stepped_bake, ANIM_OT_stepped_restore) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls)