浏览代码

write animations at the root

jackcaron 10 年之前
父节点
当前提交
8ee9c98000

+ 3 - 8
utils/exporters/blender/addons/io_three/exporter/api/mesh.py

@@ -458,7 +458,7 @@ def blend_shapes(mesh, options):
     return manifest
 
 @_mesh
-def animated_blend_shapes(mesh, options):
+def animated_blend_shapes(mesh, name, options):
     """
 
     :param mesh:
@@ -473,7 +473,7 @@ def animated_blend_shapes(mesh, options):
         animCurves = animCurves.action.fcurves
 
     for key in shp.key_blocks.keys()[1:]:    # skip "Basis"
-        key_name = ".morphTargetInfluences["+key+"]"
+        key_name = name+".morphTargetInfluences["+key+"]"
         found_animation = False
         data_path = 'key_blocks["'+key+'"].value'
         values = []
@@ -492,12 +492,7 @@ def animated_blend_shapes(mesh, options):
                 constants.KEYS: values
             });
 
-    animation = [{
-        constants.KEYFRAMES: tracks,
-        constants.FPS: context.scene.render.fps,
-        constants.NAME: "default"
-    }]
-    return animation
+    return tracks
 
 @_mesh
 def materials(mesh, options):

+ 4 - 7
utils/exporters/blender/addons/io_three/exporter/api/object.py

@@ -180,6 +180,8 @@ def animated_xform(obj, options):
         return []
     fcurves = fcurves.action.fcurves
 
+    objName = obj.name
+
     tracks = []
     i = 0
     nb_curves = len(fcurves)
@@ -202,7 +204,7 @@ def animated_xform(obj, options):
         track = []
         track_loc.append(track)
         tracks.append({
-            constants.NAME: field_info[0],
+            constants.NAME: objName+field_info[0],
             constants.TYPE: field_info[2],
             constants.KEYS: track
         })
@@ -228,12 +230,7 @@ def animated_xform(obj, options):
     context.scene.frame_set(original_frame, 0.0)  # restore to original frame
 
     # TODO: remove duplicated key frames
-
-    return [{
-        constants.KEYFRAMES: tracks,
-        constants.FPS: context.scene.render.fps,
-        constants.NAME: obj.name
-    }]
+    return tracks
 
 @_object
 def mesh(obj, options):

+ 6 - 3
utils/exporters/blender/addons/io_three/exporter/geometry.py

@@ -568,9 +568,12 @@ class Geometry(base_classes.BaseNode):
             logger.info("Parsing %s", constants.BLEND_SHAPES)
             mt = api.mesh.blend_shapes(self.node, self.options) or []
             self[constants.MORPH_TARGETS] = mt
-            if len(mt) > 0:  # there's blend shapes, let check for animation
-                self[constants.CLIPS] = api.mesh.animated_blend_shapes(self.node, self.options) or []
-
+            if len(mt) > 0 and self._scene:  # there's blend shapes, let check for animation
+                #self[constants.CLIPS] = api.mesh.animated_blend_shapes(self.node, self.options) or []
+                tracks = api.mesh.animated_blend_shapes(self.node, self[constants.NAME], self.options) or []
+                merge = self._scene[constants.ANIMATION][0][constants.KEYFRAMES]
+                for track in tracks:
+                    merge.append(track)
 
         # In the moment there is no way to add extra data to a Geomtry in
         # Three.js. In case there is some day, here is the code:

+ 6 - 1
utils/exporters/blender/addons/io_three/exporter/object.py

@@ -124,7 +124,12 @@ class Object(base_classes.BaseNode):
         no_anim = (None, False, constants.OFF)
         if self.options.get(constants.KEYFRAMES) not in no_anim:
             logger.info("Export Transform Animation for %s", self.node)
-            self[constants.CLIPS] = api.object.animated_xform(self.node, self.options)
+            if self._scene:
+                # only when exporting scene
+                tracks = api.object.animated_xform(self.node, self.options)
+                merge = self._scene[constants.ANIMATION][0][constants.KEYFRAMES]
+                for track in tracks:
+                    merge.append(track)
 
         if self.options.get(constants.HIERARCHY, False):
             for child in api.object.children(self.node, self.scene.valid_types):

+ 12 - 2
utils/exporters/blender/addons/io_three/exporter/scene.py

@@ -10,7 +10,7 @@ from . import (
     io,
     api
 )
-
+from bpy import context
 
 class Scene(base_classes.BaseScene):
     """Class that handles the contruction of a Three scene"""
@@ -22,13 +22,23 @@ class Scene(base_classes.BaseScene):
             constants.GEOMETRIES: [],
             constants.MATERIALS: [],
             constants.IMAGES: [],
-            constants.TEXTURES: []
+            constants.TEXTURES: [],
+            constants.ANIMATION: []
         }
         base_classes.BaseScene.__init__(self, filepath, options or {})
 
         source_file = api.scene_name()
         if source_file:
             self[constants.METADATA][constants.SOURCE_FILE] = source_file
+        self.__init_animation()
+
+    def __init_animation(self):
+        self[constants.ANIMATION].append({
+            constants.NAME: "default",
+            constants.FPS : context.scene.render.fps,
+            constants.KEYFRAMES: []
+        });
+        pass
 
     @property
     def valid_types(self):