Browse Source

add animation export option

refactor test scenes, able to run different configuration
Jason0214 7 years ago
parent
commit
1f1b15ce39
71 changed files with 97 additions and 39 deletions
  1. 1 1
      .gitignore
  2. 31 12
      io_scene_godot/__init__.py
  3. 19 5
      io_scene_godot/converters/animation.py
  4. 41 19
      tests/export_test_scenes.py
  5. 0 0
      tests/reference_exports/action_animation/animation_bone_transform.escn
  6. 0 0
      tests/reference_exports/action_animation/animation_object_transform.escn
  7. 0 0
      tests/reference_exports/action_animation/animation_rotation_euler.escn
  8. 0 0
      tests/reference_exports/action_animation/constraint_external_IK.escn
  9. 0 0
      tests/reference_exports/action_animation/constraint_internal_IK.escn
  10. 0 0
      tests/reference_exports/armature/armature_bone_attachment.escn
  11. 0 0
      tests/reference_exports/armature/armature_with_mesh.escn
  12. 0 0
      tests/reference_exports/armature/armature_with_non_deform_bone.escn
  13. 0 0
      tests/reference_exports/armature/armature_with_other_vertex_groups.escn
  14. 0 0
      tests/reference_exports/armature/armature_with_physics.escn
  15. 0 0
      tests/reference_exports/armature/armature_with_pose.escn
  16. 0 0
      tests/reference_exports/armature/just_armature.escn
  17. 0 0
      tests/reference_exports/camera/animation_camera.escn
  18. 0 0
      tests/reference_exports/camera/just_cameras.escn
  19. 0 0
      tests/reference_exports/light/animation_light_type_change.escn
  20. 0 0
      tests/reference_exports/light/animation_point_light_shadow.escn
  21. 0 0
      tests/reference_exports/light/animation_spot_light.escn
  22. 0 0
      tests/reference_exports/light/animation_spot_light_transform.escn
  23. 0 0
      tests/reference_exports/light/animation_sun.escn
  24. 0 0
      tests/reference_exports/light/just_point_lights.escn
  25. 0 0
      tests/reference_exports/light/just_spot_lights.escn
  26. 1 1
      tests/reference_exports/material/material_search.escn
  27. 0 0
      tests/reference_exports/material/simple_materials.escn
  28. 0 0
      tests/reference_exports/mesh/just_mesh.escn
  29. 0 0
      tests/reference_exports/mesh/parented_meshes.escn
  30. 0 0
      tests/reference_exports/mesh/physics.escn
  31. 0 0
      tests/reference_exports/mesh/tangent_test.escn
  32. 0 0
      tests/reference_exports/mesh/uv_testing.escn
  33. 0 0
      tests/reference_exports/mesh/vertex_color.escn
  34. 1 1
      tests/reference_exports/scene_animation/animation_parented_objects.escn
  35. 0 0
      tests/reference_exports/shape_key/animation_shapekey.escn
  36. 0 0
      tests/reference_exports/shape_key/just_shapekey.escn
  37. 0 0
      tests/reference_exports/shape_key/shapekey_with_multi_surface.escn
  38. 0 0
      tests/test_scenes/action_animation/animation_bone_transform.blend
  39. 0 0
      tests/test_scenes/action_animation/animation_object_transform.blend
  40. 0 0
      tests/test_scenes/action_animation/animation_rotation_euler.blend
  41. 0 0
      tests/test_scenes/action_animation/constraint_external_IK.blend
  42. 0 0
      tests/test_scenes/action_animation/constraint_internal_IK.blend
  43. 0 0
      tests/test_scenes/armature/armature_bone_attachment.blend
  44. 0 0
      tests/test_scenes/armature/armature_with_mesh.blend
  45. 0 0
      tests/test_scenes/armature/armature_with_non_deform_bone.blend
  46. 0 0
      tests/test_scenes/armature/armature_with_other_vertex_groups.blend
  47. 0 0
      tests/test_scenes/armature/armature_with_physics.blend
  48. 0 0
      tests/test_scenes/armature/armature_with_pose.blend
  49. 0 0
      tests/test_scenes/armature/just_armature.blend
  50. 0 0
      tests/test_scenes/camera/animation_camera.blend
  51. 0 0
      tests/test_scenes/camera/just_cameras.blend
  52. 0 0
      tests/test_scenes/light/animation_light_type_change.blend
  53. 0 0
      tests/test_scenes/light/animation_point_light_shadow.blend
  54. 0 0
      tests/test_scenes/light/animation_spot_light.blend
  55. 0 0
      tests/test_scenes/light/animation_spot_light_transform.blend
  56. 0 0
      tests/test_scenes/light/animation_sun.blend
  57. 0 0
      tests/test_scenes/light/just_point_lights.blend
  58. 0 0
      tests/test_scenes/light/just_spot_lights.blend
  59. 0 0
      tests/test_scenes/material/material_search.blend
  60. 0 0
      tests/test_scenes/material/simple_materials.blend
  61. 0 0
      tests/test_scenes/mesh/just_mesh.blend
  62. 0 0
      tests/test_scenes/mesh/parented_meshes.blend
  63. 0 0
      tests/test_scenes/mesh/physics.blend
  64. 0 0
      tests/test_scenes/mesh/tangent_test.blend
  65. 0 0
      tests/test_scenes/mesh/uv_testing.blend
  66. 0 0
      tests/test_scenes/mesh/vertex_color.blend
  67. 0 0
      tests/test_scenes/scene_animation/animation_parented_objects.blend
  68. 3 0
      tests/test_scenes/scene_animation/config.json
  69. 0 0
      tests/test_scenes/shape_key/animation_shapekey.blend
  70. 0 0
      tests/test_scenes/shape_key/just_shapekey.blend
  71. 0 0
      tests/test_scenes/shape_key/shapekey_with_multi_surface.blend

+ 1 - 1
.gitignore

@@ -2,7 +2,7 @@
 __pycache__
 
 *.blend[0-9]
-tests/godot_project/exports/*.escn
+tests/godot_project/exports/*
 
 .import 
 *.import

+ 31 - 12
io_scene_godot/__init__.py

@@ -82,7 +82,7 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
         description="Export only selected objects (and visible in active "
                     "layers if that applies).",
         default=False,
-        )
+    )
     use_exclude_ctrl_bone = BoolProperty(
         name="Exclude Control Bones",
         description="Do not export control bones (bone.use_deform = false)",
@@ -90,28 +90,47 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
     )
     use_export_animation = BoolProperty(
         name="Export Animation",
-        description="Export all the animation actions (include those "
-                    "in nla_tracks), notice if an animated object has "
-                    "an ancestor also has animated, its animation would "
-                    "go into the ancetor's AnimationPlayer",
+        description="Export all the animation actions (include actions "
+                    "in nla_tracks), note that by default blender animation "
+                    "is exported as actions, so every node would have their "
+                    "own AnimationPlayer hold their actions",
         default=True,
-        )
-    use_seperate_animation_player = BoolProperty(
-        name="Seperate AnimationPlayer For Each Object",
-        description="Create a seperate AnimationPlayer node for every"
-                    "blender object which has animtion data",
-        default=False,
     )
     use_mesh_modifiers = BoolProperty(
         name="Apply Modifiers",
         description="Apply modifiers to mesh objects (on a copy!).",
         default=True,
-        )
+    )
     use_active_layers = BoolProperty(
         name="Active Layers",
         description="Export only objects on the active layers.",
         default=True,
+    )
+    animation_modes = EnumProperty(
+        name="Animation Modes",
+        description="Configuration of how blender animation data being "
+                    "exported to godot AnimationPlayer as well as the "
+                    "placement of AnimationPlayers in the node tree.",
+        default="ACTIONS",
+        items=(
+            (
+                "ACTIONS", "Animation as Actions",
+                "Each animated node would have their own AnimationPlayer"
+            ),
+            (
+                "SCENE_ANIMATION", "Scene Animation",
+                "All the animations of the whole scene would be placed "
+                "into one AnimationPlayer at scene root"
+            ),
+            (
+                "SQUASHED_ACTIONS", "Animation as Actions with Squash",
+                "Animation is exported as actions of nodes, but instead "
+                "of having an individual AnimationPlayer for each node, "
+                "this configuration would squash children nodes' actions "
+                "to their parents"
+            )
         )
+    )
     material_search_paths = EnumProperty(
         name="Material Search Paths",
         description="Search for existing godot materials with names that match"

+ 19 - 5
io_scene_godot/converters/animation.py

@@ -229,12 +229,26 @@ def transform_frames_to_keys(frame_list, value_list, interp):
 
 
 def get_animation_player(escn_file, export_settings, godot_node):
-    """Get a AnimationPlayer node, if not existed, a new
-    one will be created and returned"""
+    """Get a AnimationPlayer node, its return value depends
+    on animation exporting settings"""
     animation_player = None
+    # the parent of AnimationPlayer
+    animation_base = None
 
-    # looking for a existed AnimationPlayer
-    if not export_settings['use_seperate_animation_player']:
+    if export_settings['animation_modes'] == 'ACTIONS':
+        animation_base = godot_node
+    elif export_settings['animation_modes'] == 'SCENE_ANIMATION':
+        node_ptr = godot_node
+        while node_ptr.parent is not None:
+            node_ptr = node_ptr.parent
+        scene_root = node_ptr
+        animation_base = scene_root
+        for child in scene_root.children:
+            if child.get_type() == 'AnimationPlayer':
+                animation_player = child
+                break
+    else:  # export_settings['animation_modes'] == 'SQUASHED_ACTIONS':
+        animation_base = godot_node
         node_ptr = godot_node
         while node_ptr is not None:
             for child in node_ptr.children:
@@ -248,7 +262,7 @@ def get_animation_player(escn_file, export_settings, godot_node):
     if animation_player is None:
         animation_player = AnimationPlayer(
             name='AnimationPlayer',
-            parent=godot_node,
+            parent=animation_base,
         )
 
         escn_file.add_node(animation_player)

+ 41 - 19
tests/export_test_scenes.py

@@ -2,34 +2,56 @@ import bpy
 import os
 import sys
 import traceback
+import json
 
 sys.path = [os.getcwd()] + sys.path  # Ensure exporter from this folder
-from io_scene_godot import export_godot
 
+TEST_SCENE_DIR = os.path.join(os.getcwd(), "tests/test_scenes")
+EXPORTED_DIR = os.path.join(os.getcwd(), "tests/godot_project/exports")
 
-def export_escn(out_file):
+def export_escn(out_file, config):
     """Fake the export operator call"""
     import io_scene_godot
-    io_scene_godot.export(out_file, {})
+    io_scene_godot.export(out_file, config)
 
 
 def main():
-    target_dir = os.path.join(os.getcwd(), "tests/test_scenes")
-    for file_name in os.listdir(target_dir):
-        full_path = os.path.join(target_dir, file_name)
-        if full_path.endswith(".blend"):
-            print("Exporting {}".format(full_path))
-            bpy.ops.wm.open_mainfile(filepath=full_path)
-
-            out_path, blend_name = os.path.split(full_path)
-            out_path = os.path.join(
-                out_path,
-                '../godot_project/exports/',
-                blend_name.replace('.blend', '.escn')
-                )
-            print(out_path)
-            export_escn(out_path)
-            print("Exported")
+    dir_queue = list()
+    dir_queue.append('.')
+    while dir_queue:
+        dir_relpath = dir_queue.pop(0)
+
+        # read config file if present, otherwise use default
+        src_dir_path = os.path.join(TEST_SCENE_DIR, dir_relpath)
+        if os.path.exists(os.path.join(src_dir_path, "config.json")):
+            with open(os.path.join(src_dir_path, "config.json")) as config_file:
+                config = json.load(config_file)
+        else:
+            config = {}
+
+        # create exported to directory
+        exported_dir_path = os.path.join(EXPORTED_DIR, dir_relpath)
+        if not os.path.exists(exported_dir_path):
+            os.makedirs(exported_dir_path)
+
+        for item in os.listdir(os.path.join(TEST_SCENE_DIR, dir_relpath)):
+            item_abspath = os.path.join(TEST_SCENE_DIR, dir_relpath, item)
+            if os.path.isdir(item_abspath):
+                # push dir into queue for later traversal
+                dir_queue.append(os.path.join(dir_relpath, item))
+            elif item_abspath.endswith('blend'):
+                # export blend file
+                print("---------")
+                print("Exporting {}".format(os.path.abspath(item_abspath)))
+                bpy.ops.wm.open_mainfile(filepath=item_abspath)
+
+                out_path = os.path.join(
+                    EXPORTED_DIR,
+                    dir_relpath,
+                    item.replace('.blend', '.escn')
+                    )
+                export_escn(out_path, config)
+                print("Exported to {}".format(os.path.abspath(out_path)))
 
 
 def run_with_abort(function):

+ 0 - 0
tests/reference_exports/animation_bone_transform.escn → tests/reference_exports/action_animation/animation_bone_transform.escn


+ 0 - 0
tests/reference_exports/animation_object_transform.escn → tests/reference_exports/action_animation/animation_object_transform.escn


+ 0 - 0
tests/reference_exports/animation_rotation_euler.escn → tests/reference_exports/action_animation/animation_rotation_euler.escn


+ 0 - 0
tests/reference_exports/constraint_external_IK.escn → tests/reference_exports/action_animation/constraint_external_IK.escn


+ 0 - 0
tests/reference_exports/constraint_internal_IK.escn → tests/reference_exports/action_animation/constraint_internal_IK.escn


+ 0 - 0
tests/reference_exports/armature_bone_attachment.escn → tests/reference_exports/armature/armature_bone_attachment.escn


+ 0 - 0
tests/reference_exports/armature_with_mesh.escn → tests/reference_exports/armature/armature_with_mesh.escn


+ 0 - 0
tests/reference_exports/armature_with_non_deform_bone.escn → tests/reference_exports/armature/armature_with_non_deform_bone.escn


+ 0 - 0
tests/reference_exports/armature_with_other_vertex_groups.escn → tests/reference_exports/armature/armature_with_other_vertex_groups.escn


+ 0 - 0
tests/reference_exports/armature_with_physics.escn → tests/reference_exports/armature/armature_with_physics.escn


+ 0 - 0
tests/reference_exports/armature_with_pose.escn → tests/reference_exports/armature/armature_with_pose.escn


+ 0 - 0
tests/reference_exports/just_armature.escn → tests/reference_exports/armature/just_armature.escn


+ 0 - 0
tests/reference_exports/animation_camera.escn → tests/reference_exports/camera/animation_camera.escn


+ 0 - 0
tests/reference_exports/just_cameras.escn → tests/reference_exports/camera/just_cameras.escn


+ 0 - 0
tests/reference_exports/animation_light_type_change.escn → tests/reference_exports/light/animation_light_type_change.escn


+ 0 - 0
tests/reference_exports/animation_point_light_shadow.escn → tests/reference_exports/light/animation_point_light_shadow.escn


+ 0 - 0
tests/reference_exports/animation_spot_light.escn → tests/reference_exports/light/animation_spot_light.escn


+ 0 - 0
tests/reference_exports/animation_spot_light_transform.escn → tests/reference_exports/light/animation_spot_light_transform.escn


+ 0 - 0
tests/reference_exports/animation_sun.escn → tests/reference_exports/light/animation_sun.escn


+ 0 - 0
tests/reference_exports/just_point_lights.escn → tests/reference_exports/light/just_point_lights.escn


+ 0 - 0
tests/reference_exports/just_spot_lights.escn → tests/reference_exports/light/just_spot_lights.escn


+ 1 - 1
tests/reference_exports/material_search.escn → tests/reference_exports/material/material_search.escn

@@ -1,5 +1,5 @@
 [gd_scene load_steps=1 format=2]
-[ext_resource id=1 path="../uv_tester_material.tres" type="SpatialMaterial"]
+[ext_resource id=1 path="../../uv_tester_material.tres" type="SpatialMaterial"]
 
 [sub_resource id=1 type="ArrayMesh"]
 

+ 0 - 0
tests/reference_exports/simple_materials.escn → tests/reference_exports/material/simple_materials.escn


+ 0 - 0
tests/reference_exports/just_mesh.escn → tests/reference_exports/mesh/just_mesh.escn


+ 0 - 0
tests/reference_exports/parented_meshes.escn → tests/reference_exports/mesh/parented_meshes.escn


+ 0 - 0
tests/reference_exports/physics.escn → tests/reference_exports/mesh/physics.escn


+ 0 - 0
tests/reference_exports/tangent_test.escn → tests/reference_exports/mesh/tangent_test.escn


+ 0 - 0
tests/reference_exports/uv_testing.escn → tests/reference_exports/mesh/uv_testing.escn


+ 0 - 0
tests/reference_exports/vertex_color.escn → tests/reference_exports/mesh/vertex_color.escn


File diff suppressed because it is too large
+ 1 - 1
tests/reference_exports/scene_animation/animation_parented_objects.escn


+ 0 - 0
tests/reference_exports/animation_shapekey.escn → tests/reference_exports/shape_key/animation_shapekey.escn


+ 0 - 0
tests/reference_exports/just_shapekey.escn → tests/reference_exports/shape_key/just_shapekey.escn


+ 0 - 0
tests/reference_exports/shapekey_with_multi_surface.escn → tests/reference_exports/shape_key/shapekey_with_multi_surface.escn


+ 0 - 0
tests/test_scenes/animation_bone_transform.blend → tests/test_scenes/action_animation/animation_bone_transform.blend


+ 0 - 0
tests/test_scenes/animation_object_transform.blend → tests/test_scenes/action_animation/animation_object_transform.blend


+ 0 - 0
tests/test_scenes/animation_rotation_euler.blend → tests/test_scenes/action_animation/animation_rotation_euler.blend


+ 0 - 0
tests/test_scenes/constraint_external_IK.blend → tests/test_scenes/action_animation/constraint_external_IK.blend


+ 0 - 0
tests/test_scenes/constraint_internal_IK.blend → tests/test_scenes/action_animation/constraint_internal_IK.blend


+ 0 - 0
tests/test_scenes/armature_bone_attachment.blend → tests/test_scenes/armature/armature_bone_attachment.blend


+ 0 - 0
tests/test_scenes/armature_with_mesh.blend → tests/test_scenes/armature/armature_with_mesh.blend


+ 0 - 0
tests/test_scenes/armature_with_non_deform_bone.blend → tests/test_scenes/armature/armature_with_non_deform_bone.blend


+ 0 - 0
tests/test_scenes/armature_with_other_vertex_groups.blend → tests/test_scenes/armature/armature_with_other_vertex_groups.blend


+ 0 - 0
tests/test_scenes/armature_with_physics.blend → tests/test_scenes/armature/armature_with_physics.blend


+ 0 - 0
tests/test_scenes/armature_with_pose.blend → tests/test_scenes/armature/armature_with_pose.blend


+ 0 - 0
tests/test_scenes/just_armature.blend → tests/test_scenes/armature/just_armature.blend


+ 0 - 0
tests/test_scenes/animation_camera.blend → tests/test_scenes/camera/animation_camera.blend


+ 0 - 0
tests/test_scenes/just_cameras.blend → tests/test_scenes/camera/just_cameras.blend


+ 0 - 0
tests/test_scenes/animation_light_type_change.blend → tests/test_scenes/light/animation_light_type_change.blend


+ 0 - 0
tests/test_scenes/animation_point_light_shadow.blend → tests/test_scenes/light/animation_point_light_shadow.blend


+ 0 - 0
tests/test_scenes/animation_spot_light.blend → tests/test_scenes/light/animation_spot_light.blend


+ 0 - 0
tests/test_scenes/animation_spot_light_transform.blend → tests/test_scenes/light/animation_spot_light_transform.blend


+ 0 - 0
tests/test_scenes/animation_sun.blend → tests/test_scenes/light/animation_sun.blend


+ 0 - 0
tests/test_scenes/just_point_lights.blend → tests/test_scenes/light/just_point_lights.blend


+ 0 - 0
tests/test_scenes/just_spot_lights.blend → tests/test_scenes/light/just_spot_lights.blend


+ 0 - 0
tests/test_scenes/material_search.blend → tests/test_scenes/material/material_search.blend


+ 0 - 0
tests/test_scenes/simple_materials.blend → tests/test_scenes/material/simple_materials.blend


+ 0 - 0
tests/test_scenes/just_mesh.blend → tests/test_scenes/mesh/just_mesh.blend


+ 0 - 0
tests/test_scenes/parented_meshes.blend → tests/test_scenes/mesh/parented_meshes.blend


+ 0 - 0
tests/test_scenes/physics.blend → tests/test_scenes/mesh/physics.blend


+ 0 - 0
tests/test_scenes/tangent_test.blend → tests/test_scenes/mesh/tangent_test.blend


+ 0 - 0
tests/test_scenes/uv_testing.blend → tests/test_scenes/mesh/uv_testing.blend


+ 0 - 0
tests/test_scenes/vertex_color.blend → tests/test_scenes/mesh/vertex_color.blend


+ 0 - 0
tests/test_scenes/animation_parented_objects.blend → tests/test_scenes/scene_animation/animation_parented_objects.blend


+ 3 - 0
tests/test_scenes/scene_animation/config.json

@@ -0,0 +1,3 @@
+{
+    "animation_modes": "SCENE_ANIMATION" 
+}

+ 0 - 0
tests/test_scenes/animation_shapekey.blend → tests/test_scenes/shape_key/animation_shapekey.blend


+ 0 - 0
tests/test_scenes/just_shapekey.blend → tests/test_scenes/shape_key/just_shapekey.blend


+ 0 - 0
tests/test_scenes/shapekey_with_multi_surface.blend → tests/test_scenes/shape_key/shapekey_with_multi_surface.blend


Some files were not shown because too many files changed in this diff