Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
for group in limb_generated_names:
if b.name in limb_generated_names[group].values() or b.name in limb_generated_names[group]['controls']\
or b.name in limb_generated_names[group]['ik_ctrl']:
names = limb_generated_names[group]
if names['limb_type'] == 'arm':
func = arm_ik2fk
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[0]].bone.select = True
rig.pose.bones[controls[4]].bone.select = True
rig.pose.bones[pole].bone.select = True
rig.pose.bones[parent].bone.select = True
kwargs = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1], 'hand_ik': controls[4],
'pole': pole, 'main_parent': parent}
args = (controls[0], controls[1], controls[2], controls[3],
controls[4], pole, parent)
else:
func = leg_ik2fk
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[0]].bone.select = True
rig.pose.bones[controls[6]].bone.select = True
rig.pose.bones[controls[5]].bone.select = True
rig.pose.bones[pole].bone.select = True
rig.pose.bones[parent].bone.select = True
kwargs = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
'foot_ik': controls[6], 'pole': pole, 'footroll': controls[5], 'mfoot_ik': ik_ctrl[2],
'main_parent': parent}
args = (controls[0], controls[1], controls[2], controls[3],
controls[6], controls[5], pole, parent)
for f in frames:
if not bones_in_frame(f, rig, *args):
continue
scn.frame_set(f)
func(**kwargs)
bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot')
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
bpy.ops.pose.select_all(action='DESELECT')
limb_generated_names.pop(group)
break
def IktoFk(rig, window='ALL'):
scn = bpy.context.scene
id_store = bpy.context.window_manager
rig_id = rig.data['rig_id']
leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id)
arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id)
limb_generated_names = get_limb_generated_names(rig)
if window == 'ALL':
frames = get_keyed_frames_in_range(bpy.context, rig)
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
elif window == 'CURRENT':
frames = [scn.frame_current]
else:
frames = [scn.frame_current]
if not id_store.rigify_transfer_only_selected:
bpy.ops.pose.select_all(action='DESELECT')
pbones = rig.pose.bones
else:
pbones = bpy.context.selected_pose_bones
bpy.ops.pose.select_all(action='DESELECT')
for b in pbones:
for group in limb_generated_names:
if b.name in limb_generated_names[group].values() or b.name in limb_generated_names[group]['controls']\
or b.name in limb_generated_names[group]['ik_ctrl']:
names = limb_generated_names[group]
if names['limb_type'] == 'arm':
func = arm_fk2ik
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[1]].bone.select = True
rig.pose.bones[controls[2]].bone.select = True
rig.pose.bones[controls[3]].bone.select = True
kwargs = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1],
'hand_ik': controls[4]}
args = (controls[0], controls[1], controls[2], controls[3],
controls[4], pole, parent)
else:
func = leg_fk2ik
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[1]].bone.select = True
rig.pose.bones[controls[2]].bone.select = True
rig.pose.bones[controls[3]].bone.select = True
kwargs = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
'foot_ik': ik_ctrl[2], 'mfoot_ik': ik_ctrl[2]}
args = (controls[0], controls[1], controls[2], controls[3],
controls[6], controls[5], pole, parent)
for f in frames:
if not bones_in_frame(f, rig, *args):
continue
scn.frame_set(f)
func(**kwargs)
bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot')
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
bpy.ops.pose.select_all(action='DESELECT')
limb_generated_names.pop(group)
break
def clearAnimation(act, anim_type, names):
bones = []
for group in names:
if names[group]['limb_type'] == 'arm':
bones.extend([names[group]['controls'][0], names[group]['controls'][4]])
bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3]])
else:
bones.extend([names[group]['controls'][0], names[group]['controls'][6], names[group]['controls'][5],
names[group]['controls'][4]])
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3],
names[group]['controls'][4]])
FCurves = []
for fcu in act.fcurves:
words = fcu.data_path.split('"')
if (words[0] == "pose.bones[" and
words[1] in bones):
FCurves.append(fcu)
if FCurves == []:
return
for fcu in FCurves:
act.fcurves.remove(fcu)
# Put cleared bones back to rest pose
bpy.ops.pose.loc_clear()
bpy.ops.pose.rot_clear()
bpy.ops.pose.scale_clear()
# updateView3D()
def rotPoleToggle(rig, window='ALL', value=False, toggle=False, bake=False):
scn = bpy.context.scene
id_store = bpy.context.window_manager
rig_id = rig.data['rig_id']
leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id)
arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id)
leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id)
arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id)
limb_generated_names = get_limb_generated_names(rig)
if window == 'ALL':
frames = get_keyed_frames_in_range(bpy.context, rig)
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
elif window == 'CURRENT':
frames = [scn.frame_current]
else:
frames = [scn.frame_current]
if not id_store.rigify_transfer_only_selected:
bpy.ops.pose.select_all(action='DESELECT')
pbones = rig.pose.bones
else:
pbones = bpy.context.selected_pose_bones
bpy.ops.pose.select_all(action='DESELECT')
for b in pbones:
for group in limb_generated_names:
names = limb_generated_names[group]
if toggle:
new_pole_vector_value = not rig.pose.bones[names['parent']]['pole_vector']
else:
new_pole_vector_value = value
if b.name in names.values() or b.name in names['controls'] or b.name in names['ik_ctrl']:
if names['limb_type'] == 'arm':
func1 = arm_fk2ik
func2 = arm_ik2fk
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[0]].bone.select = not new_pole_vector_value
rig.pose.bones[controls[4]].bone.select = not new_pole_vector_value
rig.pose.bones[parent].bone.select = not new_pole_vector_value
rig.pose.bones[pole].bone.select = new_pole_vector_value
kwargs1 = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1],
'hand_ik': controls[4]}
kwargs2 = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1], 'hand_ik': controls[4],
'pole': pole, 'main_parent': parent}
args = (controls[0], controls[4], pole, parent)
else:
func1 = leg_fk2ik
func2 = leg_ik2fk
controls = names['controls']
ik_ctrl = names['ik_ctrl']
fk_ctrl = names['fk_ctrl']
parent = names['parent']
pole = names['pole']
rig.pose.bones[controls[0]].bone.select = not new_pole_vector_value
rig.pose.bones[controls[6]].bone.select = not new_pole_vector_value
rig.pose.bones[controls[5]].bone.select = not new_pole_vector_value
rig.pose.bones[parent].bone.select = not new_pole_vector_value
rig.pose.bones[pole].bone.select = new_pole_vector_value
kwargs1 = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
'foot_ik': ik_ctrl[2], 'mfoot_ik': ik_ctrl[2]}
kwargs2 = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
'foot_ik': controls[6], 'pole': pole, 'footroll': controls[5], 'mfoot_ik': ik_ctrl[2],
'main_parent': parent}
args = (controls[0], controls[6], controls[5], pole, parent)
for f in frames:
if bake and not bones_in_frame(f, rig, *args):
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
continue
scn.frame_set(f)
func1(**kwargs1)
rig.pose.bones[names['parent']]['pole_vector'] = new_pole_vector_value
func2(**kwargs2)
if bake:
bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot')
bpy.ops.anim.keyframe_insert_menu(type='Scaling')
overwrite_prop_animation(rig, rig.pose.bones[parent], 'pole_vector', new_pole_vector_value, [f])
bpy.ops.pose.select_all(action='DESELECT')
limb_generated_names.pop(group)
break
scn.frame_set(0)
class OBJECT_OT_IK2FK(bpy.types.Operator):
""" Snaps IK limb on FK limb at current frame"""
bl_idname = "rigify.ik2fk"
bl_label = "IK2FK"
bl_description = "Snaps IK limb on FK"
bl_options = {'INTERNAL'}
def execute(self,context):
rig = context.object
id_store = context.window_manager
FktoIk(rig, window='CURRENT')
return {'FINISHED'}
class OBJECT_OT_FK2IK(bpy.types.Operator):
""" Snaps FK limb on IK limb at current frame"""
bl_idname = "rigify.fk2ik"
bl_label = "FK2IK"
bl_description = "Snaps FK limb on IK"
bl_options = {'INTERNAL'}
def execute(self,context):
rig = context.object
IktoFk(rig, window='CURRENT')
return {'FINISHED'}
class OBJECT_OT_TransferFKtoIK(bpy.types.Operator):
"""Transfers FK animation to IK"""
bl_idname = "rigify.transfer_fk_to_ik"
bl_label = "Transfer FK anim to IK"
bl_description = "Transfer FK animation to IK bones"
bl_options = {'INTERNAL'}
def execute(self, context):
rig = context.object
id_store = context.window_manager
FktoIk(rig)
return {'FINISHED'}
class OBJECT_OT_TransferIKtoFK(bpy.types.Operator):
"""Transfers FK animation to IK"""
bl_idname = "rigify.transfer_ik_to_fk"
bl_label = "Transfer IK anim to FK"
bl_description = "Transfer IK animation to FK bones"
bl_options = {'INTERNAL'}
def execute(self, context):
rig = context.object
IktoFk(rig)
return {'FINISHED'}
class OBJECT_OT_ClearAnimation(bpy.types.Operator):
bl_idname = "rigify.clear_animation"
bl_label = "Clear Animation"
bl_description = "Clear Animation For FK or IK Bones"
bl_options = {'INTERNAL'}
def execute(self, context):
Alexander Gavrilov
committed
rig = context.object
scn = context.scene
if not rig.animation_data:
return {'FINISHED'}
act = rig.animation_data.action
if not act:
return {'FINISHED'}
Alexander Gavrilov
committed
clearAnimation(act, self.anim_type, names=get_limb_generated_names(rig))
return {'FINISHED'}
class OBJECT_OT_Rot2Pole(bpy.types.Operator):
bl_idname = "rigify.rotation_pole"
bl_label = "Rotation - Pole toggle"
bl_description = "Toggles IK chain between rotation and pole target"
bl_options = {'INTERNAL'}
bone_name: StringProperty(default='')
window: StringProperty(default='ALL')
toggle: BoolProperty(default=True)
value: BoolProperty(default=True)
bake: BoolProperty(default=True)
def execute(self, context):
rig = context.object
if self.bone_name:
bpy.ops.pose.select_all(action='DESELECT')
rig.pose.bones[self.bone_name].bone.select = True
rotPoleToggle(rig, window=self.window, toggle=self.toggle, value=self.value, bake=self.bake)
return {'FINISHED'}
### Registering ###
classes = (
DATA_OT_rigify_add_bone_groups,
DATA_OT_rigify_use_standard_colors,
DATA_OT_rigify_apply_selection_colors,
DATA_OT_rigify_bone_group_add,
DATA_OT_rigify_bone_group_add_theme,
DATA_OT_rigify_bone_group_remove,
DATA_OT_rigify_bone_group_remove_all,
DATA_UL_rigify_bone_groups,
DATA_MT_rigify_bone_groups_context_menu,
DATA_PT_rigify,
DATA_PT_rigify_advanced,
DATA_PT_rigify_bone_groups,
DATA_PT_rigify_layer_names,
BONE_PT_rigify_buttons,
VIEW3D_PT_rigify_animation_tools,
VIEW3D_PT_tools_rigify_dev,
LayerInit,
Generate,
UpgradeMetarigTypes,
Sample,
VIEW3D_MT_rigify,
EncodeMetarig,
EncodeMetarigSample,
EncodeWidget,
OBJECT_OT_FK2IK,
OBJECT_OT_IK2FK,
OBJECT_OT_TransferFKtoIK,
OBJECT_OT_TransferIKtoFK,
OBJECT_OT_ClearAnimation,
OBJECT_OT_Rot2Pole,
)
animation_register()
# Classes.
for cls in classes:
register_class(cls)
bpy.types.VIEW3D_MT_editor_menus.append(draw_rigify_menu)
bpy.types.VIEW3D_MT_edit_mesh.prepend(draw_mesh_edit_menu)
rot_mode.register()
rot_mode.unregister()
# Classes.
for cls in classes:
unregister_class(cls)
bpy.types.VIEW3D_MT_editor_menus.remove(draw_rigify_menu)
bpy.types.VIEW3D_MT_edit_mesh.remove(draw_mesh_edit_menu)
animation_unregister()