Skip to content

Commit c295674

Browse files
authored
Added fix for Child Of constraints.
Child of constraints should no longer corrupt animation export when scaling, make sure to clear all pose transforms before exporting though. Just wanted to add this in to 1.2 before i make it into a previous release.
1 parent 0abf468 commit c295674

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

MMT_Export_FBX.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ def draw(self, context):
3737
self.layout.label(text=message)
3838

3939
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
40-
40+
41+
# fixes child of constraints after scaling...
42+
def Fix_Child_Of_Constraints(armature):
43+
bpy.ops.object.mode_set(mode='POSE')
44+
for p_bone in armature.pose.bones:
45+
for constraint in p_bone.constraints:
46+
if constraint.type == 'CHILD_OF':
47+
bpy.context.active_object.data.bones.active = p_bone.bone
48+
context_copy = bpy.context.copy()
49+
context_copy["constraint"] = p_bone.constraints[constraint.name]
50+
bpy.ops.constraint.childof_clear_inverse(context_copy, constraint=constraint.name, owner='BONE')
51+
bpy.ops.constraint.childof_set_inverse(context_copy, constraint=constraint.name, owner='BONE')
52+
bpy.ops.object.mode_set(mode='OBJECT')
53+
4154
# sets animation location scale to and from UE4... (this bit can take a few minutes if you have many keyframes or are batch exporting, it does a lot of work!)
4255
def A_UE4_Scale(action, float, armature):
4356
bpy.ops.object.mode_set(mode='POSE')
@@ -85,6 +98,8 @@ def O_UE4_Scale(objects, float):
8598
for obj in objects:
8699
bpy.context.view_layer.objects.active = obj
87100
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
101+
if obj.type == 'ARMATURE':
102+
Fix_Child_Of_Constraints(obj)
88103
# return active object...
89104
bpy.context.view_layer.objects.active = active
90105

@@ -216,4 +231,4 @@ def Export(MMT):
216231
E_Meshes(bpy.context.selected_objects, MMT)
217232

218233
# used for testing...
219-
#Export(bpy.context.scene.JK_MMT)
234+
#Export(bpy.context.scene.JK_MMT)

0 commit comments

Comments
 (0)