Browse Source

Merge branch 'multipleanimations' of https://github.com/Digitoxin/three.js into dev

Mr.doob 11 years ago
parent
commit
9a1d1fec66

+ 2 - 1
src/loaders/JSONLoader.js

@@ -444,8 +444,9 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 		}
 
 		geometry.bones = json.bones;
+		// could change this to json.animations[0] or remove completely
 		geometry.animation = json.animation;
-
+		geometry.animations = json.animations;
 	};
 
 	function parseMorphing( scale ) {

+ 1 - 1
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/__init__.py

@@ -221,7 +221,7 @@ def save_settings_export(properties):
     "option_vertices_truncate" : properties.option_vertices_truncate,
     "option_scale"        : properties.option_scale,
 
-    "align_model"         : properties.align_model
+    "align_model"         : properties.align_model,
     }
 
     fname = get_settings_fullpath()

+ 14 - 5
utils/exporters/blender/2.66/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -267,7 +267,7 @@ TEMPLATE_MODEL_ASCII = """\
 
 	"skinWeights" : [%(weights)s],
 
-	"animation" : {%(animation)s}
+        "animations" : [%(animations)s]
 """
 
 TEMPLATE_VERTEX = "%g,%g,%g"
@@ -845,14 +845,14 @@ def generate_indices_and_weights(meshes, option_skinning):
 # (only the first action will exported)
 # ##############################################################################
 
-def generate_animation(option_animation_skeletal, option_frame_step, flipyz):
+def generate_animation(option_animation_skeletal, option_frame_step, flipyz, action_index):
 
-    if not option_animation_skeletal or len(bpy.data.actions) == 0:
+    if not option_animation_skeletal or len(bpy.data.actions) == 0 or len(bpy.data.actions) == 0:
         return ""
 
     # TODO: Add scaling influences
 
-    action = bpy.data.actions[0]
+    action = bpy.data.actions[action_index]
     armature, armatureObject = get_armature()
     if armature is None or armatureObject is None:
         return "", 0
@@ -932,6 +932,15 @@ def generate_animation(option_animation_skeletal, option_frame_step, flipyz):
 
     return animation_string
 
+def generate_all_animations(option_animation_skeletal, option_frame_step, flipyz):
+    all_animations_string = ""
+    if option_animation_skeletal:
+        for index in range(0, len(bpy.data.actions)):
+            if index != 0 :
+                all_animations_string += ", \n"
+            all_animations_string += "{" + generate_animation(option_animation_skeletal, option_frame_step, flipyz, index) + "}"
+    return all_animations_string
+
 def handle_position_channel(channel, frame, position):
 
     change = False
@@ -1390,7 +1399,7 @@ def generate_ascii_model(meshes, morphs,
     "bones"     : bones_string,
     "indices"   : indices_string,
     "weights"   : weights_string,
-    "animation" : generate_animation(option_animation_skeletal, option_frame_step, flipyz)
+    "animations" : generate_all_animations(option_animation_skeletal, option_frame_step, flipyz)
     }
 
     text = TEMPLATE_FILE_ASCII % {