Skip to content

Commit 5d3746c

Browse files
committed
anim tools fix: selection of one chain per cycle. overwrite frames already animated
1 parent 97b7478 commit 5d3746c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

ui.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .utils import write_metarig, write_widget
2727
from .utils import unique_name
2828
from .utils import upgradeMetarigTypes, outdated_types
29-
from .utils import get_keyed_frames
29+
from .utils import get_keyed_frames, bones_in_frame
3030
from .utils import overwrite_prop_animation
3131
from .rigs.utils import get_limb_generated_names
3232
from . import rig_lists
@@ -905,7 +905,7 @@ def FktoIk(rig, window='ALL'):
905905

906906
if not id_store.rigify_transfer_only_selected:
907907
pbones = rig.pose.bones
908-
bpy.ops.pose.select_all(action='SELECT')
908+
bpy.ops.pose.select_all(action='DESELECT')
909909
else:
910910
pbones = bpy.context.selected_pose_bones
911911
bpy.ops.pose.select_all(action='DESELECT')
@@ -929,6 +929,8 @@ def FktoIk(rig, window='ALL'):
929929
kwargs = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
930930
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1], 'hand_ik': controls[4],
931931
'pole': pole, 'main_parent': parent}
932+
args = (controls[0], controls[1], controls[2], controls[3],
933+
ik_ctrl[1], controls[4], pole)
932934
else:
933935
func = leg_ik2fk
934936
controls = names['controls']
@@ -945,13 +947,18 @@ def FktoIk(rig, window='ALL'):
945947
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
946948
'foot_ik': controls[6], 'pole': pole, 'footroll': controls[5], 'mfoot_ik': ik_ctrl[2],
947949
'main_parent': parent}
950+
args = (controls[0], controls[1], controls[2], controls[3],
951+
ik_ctrl[1], controls[6], controls[5], pole)
948952

949953
for f in frames:
954+
if not bones_in_frame(f, rig, *args):
955+
continue
950956
scn.frame_set(f)
951957
func(**kwargs)
952958
bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot')
953959
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
954960

961+
bpy.ops.pose.select_all(action='DESELECT')
955962
limb_generated_names.pop(group)
956963
break
957964

@@ -973,9 +980,11 @@ def IktoFk(rig, window='ALL'):
973980
frames = [f for f in frames if f in range(id_store.rigify_transfer_start_frame, id_store.rigify_transfer_end_frame+1)]
974981
elif window == 'CURRENT':
975982
frames = [scn.frame_current]
983+
else:
984+
frames = [scn.frame_current]
976985

977986
if not id_store.rigify_transfer_only_selected:
978-
bpy.ops.pose.select_all(action='SELECT')
987+
bpy.ops.pose.select_all(action='DESELECT')
979988
pbones = rig.pose.bones
980989
else:
981990
pbones = bpy.context.selected_pose_bones
@@ -999,6 +1008,8 @@ def IktoFk(rig, window='ALL'):
9991008
kwargs = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
10001009
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1],
10011010
'hand_ik': controls[4]}
1011+
args = (controls[0], controls[1], controls[2], controls[3],
1012+
ik_ctrl[1], controls[4], pole)
10021013
else:
10031014
func = leg_fk2ik
10041015
controls = names['controls']
@@ -1012,11 +1023,18 @@ def IktoFk(rig, window='ALL'):
10121023
kwargs = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
10131024
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
10141025
'foot_ik': ik_ctrl[2], 'mfoot_ik': ik_ctrl[2]}
1026+
args = (controls[0], controls[1], controls[2], controls[3],
1027+
ik_ctrl[1], controls[6], controls[5], pole)
1028+
10151029
for f in frames:
1030+
if not bones_in_frame(f, rig, *args):
1031+
continue
10161032
scn.frame_set(f)
10171033
func(**kwargs)
10181034
bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot')
10191035
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
1036+
1037+
bpy.ops.pose.select_all(action='DESELECT')
10201038
limb_generated_names.pop(group)
10211039
break
10221040

utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,29 @@ def get_keyed_frames(rig):
12101210
return frames
12111211

12121212

1213+
def bones_in_frame(f, rig, *args):
1214+
"""
1215+
True if one of the bones listed in args is animated at frame f
1216+
:param f: the frame
1217+
:param rig: the rig
1218+
:param args: bone names
1219+
:return:
1220+
"""
1221+
1222+
if rig.animation_data and rig.animation_data.action:
1223+
fcus = rig.animation_data.action.fcurves
1224+
else:
1225+
return False
1226+
1227+
for fc in fcus:
1228+
animated_frames = [kp.co[0] for kp in fc.keyframe_points]
1229+
for bone in args:
1230+
if bone in fc.data_path.split('"') and f in animated_frames:
1231+
return True
1232+
1233+
return False
1234+
1235+
12131236
def overwrite_prop_animation(rig, bone, prop_name, value, frames):
12141237
act = rig.animation_data.action
12151238
if not act:

0 commit comments

Comments
 (0)