ソースを参照

Fixing blender exporter about bones animations

David Catuhe 11 年 前
コミット
01ffa7e51c

+ 1 - 0
Babylon/Loading/babylon.sceneLoader.js

@@ -48,6 +48,7 @@ var BABYLON = BABYLON || {};
                 }
 
                 if (onsuccess) {
+                    scene.importedMeshesFiles.push(rootUrl + sceneFilename);
                     onsuccess(meshes, particleSystems, skeletons);
                 }
             }, progressCallBack, database);

+ 4 - 2
Babylon/Materials/babylon.standardMaterial.js

@@ -6,6 +6,8 @@
 };
 var BABYLON;
 (function (BABYLON) {
+    var maxSimultaneousLights = 4;
+
     var StandardMaterial = (function (_super) {
         __extends(StandardMaterial, _super);
         function StandardMaterial(name, scene) {
@@ -196,7 +198,7 @@ var BABYLON;
                     }
 
                     lightIndex++;
-                    if (lightIndex == 4)
+                    if (lightIndex == maxSimultaneousLights)
                         break;
                 }
             }
@@ -387,7 +389,7 @@ var BABYLON;
 
                     lightIndex++;
 
-                    if (lightIndex == 4)
+                    if (lightIndex == maxSimultaneousLights)
                         break;
                 }
             }

+ 4 - 2
Babylon/Materials/babylon.standardMaterial.ts

@@ -1,4 +1,6 @@
 module BABYLON {
+    var maxSimultaneousLights = 4;
+
     export class StandardMaterial extends Material {
         public diffuseTexture: Texture;
         public ambientTexture: Texture;
@@ -199,7 +201,7 @@
                     }
 
                     lightIndex++;
-                    if (lightIndex == 4)
+                    if (lightIndex == maxSimultaneousLights)
                         break;
                 }
             }
@@ -393,7 +395,7 @@
 
                     lightIndex++;
 
-                    if (lightIndex == 4)
+                    if (lightIndex == maxSimultaneousLights)
                         break;
                 }
             }

+ 2 - 0
Babylon/babylon.scene.js

@@ -63,6 +63,8 @@
             // Customs render targets
             this.renderTargetsEnabled = true;
             this.customRenderTargets = new Array();
+            // Imported meshes
+            this.importedMeshesFiles = new Array();
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;

+ 3 - 0
Babylon/babylon.scene.ts

@@ -94,6 +94,9 @@
         // Delay loading
         public useDelayedTextureLoading: boolean;
 
+        // Imported meshes
+        public importedMeshesFiles = new Array<String>();
+
         // Database
         public database; //ANY
 

+ 14 - 7
Exporters/Blender/io_export_babylon.py

@@ -779,13 +779,13 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
         file_handler.write("]")         
         file_handler.write("}") 
 
-    def export_bone_matrix(armature, bone, label, file_handler):
+    def get_bone_matrix(armature, bone):
         SystemMatrix = Matrix.Scale(-1, 4, Vector((0, 0, 1))) * Matrix.Rotation(radians(-90), 4, 'X')
 
         if (bone.parent):
-            Export_babylon.write_matrix4(file_handler, label, (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() * (SystemMatrix * armature.matrix_world * bone.matrix))
+            return (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() * (SystemMatrix * armature.matrix_world * bone.matrix)
         else:
-            Export_babylon.write_matrix4(file_handler, label, SystemMatrix * armature.matrix_world * bone.matrix)
+            return SystemMatrix * armature.matrix_world * bone.matrix
 
 
     def export_bones(armature, scene, file_handler, id):
@@ -807,7 +807,7 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
             Export_babylon.write_string(file_handler, "name", bone.name, True)
             Export_babylon.write_int(file_handler, "index", j)
 
-            Export_babylon.export_bone_matrix(armature, bone, "matrix", file_handler)
+            Export_babylon.write_matrix4(file_handler, "matrix", Export_babylon.get_bone_matrix(armature, bone))
 
             if (bone.parent):
                 parentId = 0
@@ -844,15 +844,22 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
 
         #keys
         file_handler.write(",\"keys\":[")
+
+        previousBoneMatrix = None
                         
         for Frame in range(start_frame, end_frame + 1):
                 
+            bpy.context.scene.frame_set(Frame)
+            currentBoneMatrix = Export_babylon.get_bone_matrix(armature, bone)
+
+            if (Frame != end_frame and currentBoneMatrix == previousBoneMatrix):
+                continue
+
             file_handler.write("{")
 
             Export_babylon.write_int(file_handler, "frame", Frame, True)
-            bpy.context.scene.frame_set(Frame)
-
-            Export_babylon.export_bone_matrix(armature, bone, "values", file_handler)
+            Export_babylon.write_matrix4(file_handler, "values", currentBoneMatrix)
+            previousBoneMatrix = currentBoneMatrix
 
             if Frame == end_frame:
                 file_handler.write("}")