Remove cycle modifier using ctrl+clic
1.4.2 - added: `Ctrl + click` on Add cycle modifier remove all cycle on all fcurves (hided option to force clean)master
parent
31ab45865b
commit
dbdba01485
|
@ -1,5 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
1.4.2
|
||||||
|
|
||||||
|
- added: `Ctrl + click` on Add cycle modifier remove all cycle on all fcurves (hided option to force clean)
|
||||||
|
|
||||||
1.4.1
|
1.4.1
|
||||||
|
|
||||||
- changed: better filter for applying cycle modifier (prevent targeting prefix-reserved bones)
|
- changed: better filter for applying cycle modifier (prevent targeting prefix-reserved bones)
|
||||||
|
|
14
OP_setup.py
14
OP_setup.py
|
@ -75,16 +75,24 @@ class AW_OT_autoset_axis(bpy.types.Operator):
|
||||||
class AW_OT_create_cycles_modifiers(bpy.types.Operator):
|
class AW_OT_create_cycles_modifiers(bpy.types.Operator):
|
||||||
bl_idname = "autowalk.create_cycles_modifiers"
|
bl_idname = "autowalk.create_cycles_modifiers"
|
||||||
bl_label = "Add Cycles Modifiers"
|
bl_label = "Add Cycles Modifiers"
|
||||||
bl_description = "Add cycles modifier on all bones not starting with [mch, org, def]\
|
bl_description = "Add cycles modifier on all bones not prefixed [mch, org, def, vis,fdl]\
|
||||||
\nand that are non-deforming"
|
\nCtrl + Click : remove ALL Cycles modifiers on all fcurves"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return context.object and context.object.type == 'ARMATURE'
|
return context.object and context.object.type == 'ARMATURE'
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
self.ctrl = event.ctrl
|
||||||
|
return self.execute(context)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
fn.create_cycle_modifiers(context.object)
|
if self.ctrl:
|
||||||
|
fn.remove_all_cycles_modifier(context.object)
|
||||||
|
else:
|
||||||
|
fn.create_cycle_modifiers(context.object)
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ bl_info = {
|
||||||
"name": "Auto Walk",
|
"name": "Auto Walk",
|
||||||
"description": "Develop a walk/run cycles along a curve and pin feets",
|
"description": "Develop a walk/run cycles along a curve and pin feets",
|
||||||
"author": "Samuel Bernou",
|
"author": "Samuel Bernou",
|
||||||
"version": (1, 4, 1),
|
"version": (1, 4, 2),
|
||||||
"blender": (3, 0, 0),
|
"blender": (3, 0, 0),
|
||||||
"location": "View3D",
|
"location": "View3D",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
|
20
fn.py
20
fn.py
|
@ -625,16 +625,22 @@ class attr_set():
|
||||||
|
|
||||||
# fcurve modifiers
|
# fcurve modifiers
|
||||||
|
|
||||||
def remove_all_cycles_modifier():
|
def remove_all_cycles_modifier(ob=None):
|
||||||
for fc in bpy.context.object.animation_data.action.fcurves:
|
ob = ob or bpy.context.object
|
||||||
|
ct = 0
|
||||||
|
for fc in ob.animation_data.action.fcurves:
|
||||||
# if fc.data_path.split('"')[1] in selected_names:
|
# if fc.data_path.split('"')[1] in selected_names:
|
||||||
for m in reversed(fc.modifiers):
|
for m in reversed(fc.modifiers):
|
||||||
if m.type == 'CYCLES':
|
if m.type == 'CYCLES':
|
||||||
|
ct += 1
|
||||||
|
# print(f'Remove cycle mod on fcurve: {fc.data_path}')
|
||||||
fc.modifiers.remove(m)
|
fc.modifiers.remove(m)
|
||||||
|
fc.update()
|
||||||
|
print(f'Remove cyclic modifiers on {ct} fcurve(s)')
|
||||||
|
return ct
|
||||||
|
|
||||||
def create_cycle_modifiers(ob=None):
|
def create_cycle_modifiers(ob=None):
|
||||||
if not ob:
|
ob = ob or bpy.context.object
|
||||||
ob = bpy.context.object
|
|
||||||
|
|
||||||
# skip bones that are on protected layers ?
|
# skip bones that are on protected layers ?
|
||||||
# protected = [i for i, l in enumerate(ob.data.layers_protected) if l]
|
# protected = [i for i, l in enumerate(ob.data.layers_protected) if l]
|
||||||
|
@ -646,7 +652,7 @@ def create_cycle_modifiers(ob=None):
|
||||||
name_list = [b.name for b in ob.data.bones] # if not b.use_deform (too limiting)
|
name_list = [b.name for b in ob.data.bones] # if not b.use_deform (too limiting)
|
||||||
|
|
||||||
re_prefix = re.compile(r'^(mch|def|org|vis|fld|ctp)[\._-]', flags=re.I)
|
re_prefix = re.compile(r'^(mch|def|org|vis|fld|ctp)[\._-]', flags=re.I)
|
||||||
|
ct = 0
|
||||||
for fc in ob.animation_data.action.fcurves:
|
for fc in ob.animation_data.action.fcurves:
|
||||||
if [m for m in fc.modifiers if m.type == 'CYCLES']:
|
if [m for m in fc.modifiers if m.type == 'CYCLES']:
|
||||||
# skip already existing modifier
|
# skip already existing modifier
|
||||||
|
@ -665,7 +671,11 @@ def create_cycle_modifiers(ob=None):
|
||||||
continue
|
continue
|
||||||
# print(f'Adding cycle modifier {fc.data_path}')
|
# print(f'Adding cycle modifier {fc.data_path}')
|
||||||
_m = fc.modifiers.new(type='CYCLES')
|
_m = fc.modifiers.new(type='CYCLES')
|
||||||
|
ct += 1
|
||||||
fc.update()
|
fc.update()
|
||||||
|
|
||||||
|
print(f'Added cyclic modifiers on {ct} fcurve(s)')
|
||||||
|
return ct
|
||||||
|
|
||||||
## Get collection, create if necessary
|
## Get collection, create if necessary
|
||||||
def get_col(name, parent=None, create=True):
|
def get_col(name, parent=None, create=True):
|
||||||
|
|
Loading…
Reference in New Issue