I am currently working on exporting Rigify rigs to Unreal Engine 4. My starting point is this: https://github.com/chichige-bobo/BlenderPython/blob/master/RigifyToUnreal/RigifyToUnreal.py
which seemed to work in Blender pre-2.8.
I got quite far already. However, when switching back from EDIT mode to OBJECT mode in the script after having deleted bones in my armature, I am getting errors that I want to avoid.
Excerpt of my script:
import bpy, math
def main():
initialSelection = bpy.context.selected_objects
for obj in initialSelection:
if obj.type == 'ARMATURE':
rigifyObj = obj
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False})
newRigObj = bpy.context.object
armature = newRigObj.data
bpy.ops.object.mode_set(mode = 'EDIT')
boneNames = [['root', None, False],
['DEF-spine', 'root', False],
['DEF-spine.001', 'DEF-spine', True],
['DEF-spine.002', 'DEF-spine.001', True],
['DEF-spine.003', 'DEF-spine.002', True],
['DEF-spine.004', 'DEF-spine.003', True],
['DEF-spine.005', 'DEF-spine.004', True]
# , ...
]
deleteBones = []
for armBone in armature.edit_bones:
isFound = False
for boneName in boneNames:
if armBone.name == boneName[0]:
isFound = True
break
if not isFound:
deleteBones.append(armBone)
for deleteBone in deleteBones:
armature.edit_bones.remove(deleteBone)
bpy.ops.object.mode_set(mode = 'OBJECT')
################################################
print('############################################################')
main()
print('############################################################')
Error Log:
############################################################
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'ORG-spine.005', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.005', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'ORG-spine.004', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.004', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.004', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.004', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - pose.bones["MCH-thigh_ik_target.parent.R"].constraints["SWITCH_PARENT"].targets[5].weight[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_upper_arm_ik_pole.R"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.R.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-forearm.R"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-forearm.R"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.L.001"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["thigh_ik_target.L"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_thigh_ik_pole.L"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L.001"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["thigh_ik_target.R"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_thigh_ik_pole.R"].hide[0]
...
############################################################
I found this info: ... take care when switching out of Edit-Mode not to keep references to the edit bones or their head/tail vectors. from: https://docs.blender.org/api/current/info_gotcha.html#armature-mode-switching
I was, however, not able to resolve this by myself.
Any ideas?
Thanks! Nico