import bpy import random bl_info = { "name": "Wiggle", "author": "William Landgren", "version": (2, 0), "blender": (3, 0, 0), } def has_keyframe(ob, attr): anim = ob.animation_data if anim is not None and anim.action is not None: for fcu in anim.action.fcurves: if fcu.data_path == attr: return len(fcu.keyframe_points) > 0 return False def find_modifier(fcu, type): for modifier in fcu.modifiers: if modifier.type == type: return modifier def wiggle(ob, context): scene = context.scene mytool = scene.my_tool if has_keyframe(ob, "delta_rotation_euler") == False: ob.keyframe_insert("delta_rotation_euler") ob.keyframe_insert("delta_location") action = ob.animation_data.action for fcu in action.fcurves: if fcu.data_path == "delta_rotation_euler": random_num_sc = random.uniform(0.01, 1) random_num_st = random.uniform(25, 60) random_num_ph = random.uniform(1000, 2000 ) random_num_ph2 = random.uniform(2000, 3000 ) mod = find_modifier(fcu, "NOISE") if mod == None: mod = fcu.modifiers.new("NOISE") mod.scale = scene.my_tool.my_float_vector mod.strength = scene.my_tool.my_float_vector2 mod.phase = scene.my_tool.my_float_vector3 + random_num_ph mod.use_influence = True mod.influence = scene.my_tool.my_float_vector4 bpy.ops.transform.rotate(value = 0) action = ob.animation_data.action for fcu in action.fcurves: if fcu.data_path == "delta_location": random_num_sc = random.uniform(0.01, 1) random_num_st = random.uniform(25, 60) random_num_ph = random.uniform(1000, 2000 ) random_num_ph2 = random.uniform(2000, 3000 ) mod = find_modifier(fcu, "NOISE") if mod == None: mod = fcu.modifiers.new("NOISE") mod.scale = scene.my_tool.my_float_vector5 mod.strength = scene.my_tool.my_float_vector6 mod.phase = scene.my_tool.my_float_vector7 + random_num_ph + random_num_ph2 mod.use_influence = True mod.influence = scene.my_tool.my_float_vector8 bpy.ops.transform.rotate(value = 0) def wiggle_selected_objects(context): for ob in bpy.context.selected_objects: wiggle(ob, context) def wiggle_selected_bones(context): for bone in bpy.context.selected_pose_bones: bone.keyframe_insert('location') bone.keyframe_insert('euler_rotation') def update_when_changed(self, context): wiggle_selected_objects(context) class MyProperties(bpy.types.PropertyGroup): #rot name_rot: bpy.props.StringProperty(name ="Rotation") my_float_vector : bpy.props.FloatProperty(name= "Speed", update=update_when_changed, soft_min= 0, soft_max= 1000, default= 50) my_float_vector2 : bpy.props.FloatProperty(name= "Strength ", update=update_when_changed, soft_min= 0, soft_max= 1000, default= 0.2) my_float_vector3 : bpy.props.FloatProperty(name= "Randomize", update=update_when_changed, soft_min= -1000, soft_max= 1000, default= 1) my_float_vector4 : bpy.props.FloatProperty(name= "Influence", update=update_when_changed, subtype= "FACTOR", soft_min= 0, soft_max= 1, default= 1.0) #loc my_float_vector5 : bpy.props.FloatProperty(name= "Speed", update=update_when_changed, soft_min= 0, soft_max= 1000, default= 50) my_float_vector6 : bpy.props.FloatProperty(name= "Strength ", update=update_when_changed, soft_min= 0, soft_max= 1000, default= 0.2) my_float_vector7 : bpy.props.FloatProperty(name= "Randomize", update=update_when_changed, soft_min= -1000, soft_max= 1000, default= 1) my_float_vector8 : bpy.props.FloatProperty(name= "Influence", update=update_when_changed, subtype= "FACTOR", soft_min= 0, soft_max= 1, default= 1.0) class ADDONNAME_PT_main_panel(bpy.types.Panel): bl_label = "Wiggle" bl_idname = "ADDONNAME_PT_main_panel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Wiggle" def draw(self, context): layout = self.layout scene = context.scene mytool = scene.my_tool layout.operator("addonname.myop_operator") row = layout.row() row.label(text="Rotation") layout.prop(mytool, "my_float_vector") layout.prop(mytool, "my_float_vector2") layout.prop(mytool, "my_float_vector3") layout.prop(mytool, "my_float_vector4") row = layout.row() row.label(text="Location") layout.prop(mytool, "my_float_vector5") layout.prop(mytool, "my_float_vector6") layout.prop(mytool, "my_float_vector7") layout.prop(mytool, "my_float_vector8") class ADDONNAME_OT_my_op(bpy.types.Operator): bl_label = "Wiggle it!" bl_idname = "addonname.myop_operator" def execute(self, context): wiggle_selected_objects(context) return {'FINISHED'} classes = [MyProperties, ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op,] def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.Scene.my_tool = bpy.props.PointerProperty(type= MyProperties) def unregister(): for cls in classes: bpy.utils.unregister_class(cls) del bpy.types.Scene.my_tool if __name__ == "__main__": register()