浏览代码

Merge pull request #206 from Jason0214/force_clear_action_effect_2.8

Force a transform clear after an armature action being exporter blender 2.8
Lu Jiacheng 6 年之前
父节点
当前提交
f4b0470a04

+ 15 - 0
io_scene_godot/converters/animation/animation_data.py

@@ -2,6 +2,8 @@
 AnimationPlayer as well as distribute Blender action into various
 action exporting functions"""
 
+import bpy
+import mathutils
 from .action import (
     export_camera_action,
     export_shapekey_action,
@@ -93,6 +95,7 @@ class ObjectAnimationExporter:
             ActionStrip(active_action),
             self.animation_player.active_animation
         )
+        self.clear_action_effect()
 
         if not self.need_baking:
             # here export unmuted nla_tracks into animation resource,
@@ -108,6 +111,7 @@ class ObjectAnimationExporter:
                             ActionStrip(strip),
                             self.animation_player.active_animation
                         )
+                        self.clear_action_effect()
 
     def export_active_action_from_nla(self, escn_file, export_settings):
         """Export all unmute nla_tracks into an active action.
@@ -127,6 +131,7 @@ class ObjectAnimationExporter:
                         ActionStrip(strip),
                         self.animation_player.active_animation
                     )
+                    self.clear_action_effect()
 
     def export_stashed_track(self, escn_file, export_settings, stashed_track):
         """Export a muted nla_track, track with all its contained action
@@ -158,6 +163,7 @@ class ObjectAnimationExporter:
                     ActionStrip(strip),
                     anim_resource
                 )
+                self.clear_action_effect()
 
         if self.need_baking:
             stashed_track.mute = True
@@ -173,6 +179,15 @@ class ObjectAnimationExporter:
                             ActionStrip(strip),
                             anim_resource
                         )
+                        self.clear_action_effect()
+
+    def clear_action_effect(self):
+        """Clear side effect of exporting an action"""
+        if (isinstance(self.blender_object, bpy.types.Object) and
+                self.blender_object.pose is not None):
+            for pose_bone in self.blender_object.pose.bones:
+                rest_bone = pose_bone.bone
+                pose_bone.matrix_basis = mathutils.Matrix.Identity(4)
 
 
 def export_animation_data(escn_file, export_settings, godot_node,

+ 2 - 2
tests/reference_exports/action_animation/animation_bone_transform.escn

@@ -49,13 +49,13 @@ bones/0/bound_children = []
 bones/1/name = "Bone.001"
 bones/1/parent = 0
 bones/1/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 3.42285e-08, 0.0, -3.42285e-08, 1.0, 0.0, 0.0, -1.0)
-bones/1/pose = Transform(0.949509, 0.207304, 0.235496, -0.189531, 0.97717, -0.096008, -0.250022, 0.0465267, 0.967122, 0.0, 0.0, 0.0)
+bones/1/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/1/enabled = true
 bones/1/bound_children = []
 bones/2/name = "Bone.002"
 bones/2/parent = 1
 bones/2/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, -3.55271e-15, 0.0, 3.55271e-15, 1.0, 0.0, 0.0, -1.30874)
-bones/2/pose = Transform(0.830409, 0.381597, 0.405961, -0.321902, 0.923317, -0.20944, -0.454752, 0.0432416, 0.889567, 0.0, 0.0, 0.0)
+bones/2/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/2/enabled = true
 bones/2/bound_children = []
 

+ 1 - 1
tests/reference_exports/action_with_constraint/constraint_with_undeform_bone.escn

@@ -55,7 +55,7 @@ bones/0/bound_children = []
 bones/1/name = "Bone.002"
 bones/1/parent = -1
 bones/1/rest = Transform(-0.454064, -0.868627, -0.198275, -0.0311123, 0.23786, -0.970801, 0.890426, -0.434637, -0.135029, 0.00854362, 2.58513, -0.0545189)
-bones/1/pose = Transform(0.999995, 0.00328448, 0.000475731, -0.00328036, 0.999959, -0.00841181, -0.00050334, 0.0084102, 0.999965, 0.0, 0.0, 0.0)
+bones/1/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/1/enabled = true
 bones/1/bound_children = []
 

+ 1 - 1
tests/reference_exports/armature/armature_illegal_bone_name.escn

@@ -64,7 +64,7 @@ bones/0/bound_children = []
 bones/1/name = "bone"
 bones/1/parent = 0
 bones/1/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.0)
-bones/1/pose = Transform(0.99961, -0.00771234, -0.0268356, 0.00777253, 0.999968, 0.00213956, 0.0268182, -0.0023473, 0.999638, 0.0, 0.0, 0.0)
+bones/1/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/1/enabled = true
 bones/1/bound_children = []
 bones/2/name = "bone001"

+ 4 - 4
tests/reference_exports/armature/armature_with_non_deform_bone.escn

@@ -87,13 +87,13 @@ bones/0/bound_children = []
 bones/1/name = "Bone.003"
 bones/1/parent = 0
 bones/1/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -3.25295)
-bones/1/pose = Transform(0.915486, -0.40227, -0.00805298, 0.401138, 0.910989, 0.0958551, -0.0312235, -0.0909843, 0.995363, 0.0, 0.0, 0.0)
+bones/1/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/1/enabled = true
 bones/1/bound_children = []
 bones/2/name = "Bone.004"
 bones/2/parent = 1
 bones/2/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -1.47006)
-bones/2/pose = Transform(0.916484, -0.373658, 0.142955, 0.390535, 0.758028, -0.522375, 0.0868252, 0.534577, 0.840648, 0.0, 0.0, 0.0)
+bones/2/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/2/enabled = true
 bones/2/bound_children = []
 
@@ -116,13 +116,13 @@ transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.82603
 bones/0/name = "Bone.001"
 bones/0/parent = -1
 bones/0/rest = Transform(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0)
-bones/0/pose = Transform(0.994451, -0.09531, -0.0445356, 0.0818319, 0.966848, -0.241885, 0.0661132, 0.236898, 0.969282, 0.0, 0.0, 0.0)
+bones/0/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/0/enabled = true
 bones/0/bound_children = []
 bones/1/name = "Bone.002"
 bones/1/parent = 0
 bones/1/rest = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -0.984039)
-bones/1/pose = Transform(0.999994, -0.00299644, -0.00185484, 0.00298136, 0.999963, -0.00808109, 0.00187899, 0.00807551, 0.999966, 0.0, 0.0, 0.0)
+bones/1/pose = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
 bones/1/enabled = true
 bones/1/bound_children = []
 bones/2/name = "Bone.003"