Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 8 years ago
parent
commit
7e7d470888

+ 1 - 0
canvas2D/src/Engine/babylon.prim2dBase.ts

@@ -3134,6 +3134,7 @@
                 this._actionManager.dispose();
                 this._actionManager = null;
             }
+            this.owner.scene.stopAnimation(this);
 
             // If there's a parent, remove this object from its parent list
             if (this._parent) {

+ 1 - 0
dist/preview release/loaders/babylon.glTFFileLoader.d.ts

@@ -289,6 +289,7 @@ declare module BABYLON {
         skins: Object;
         currentScene: Object;
         extensionsUsed: string[];
+        extensionsRequired?: string[];
         buffersCount: number;
         shaderscount: number;
         scene: Scene;

+ 12 - 23
dist/preview release/loaders/babylon.glTFFileLoader.js

@@ -326,8 +326,6 @@ var BABYLON;
                     targetNode.animations.push(babylonAnimation);
                 }
                 lastAnimation = babylonAnimation;
-                gltfRuntime.scene.stopAnimation(targetNode);
-                gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
             }
         }
     };
@@ -512,18 +510,8 @@ var BABYLON;
                 newSkeleton.bones.push(existingBone);
                 continue;
             }
-            // Check if node already exists
-            var foundBone = false;
-            for (var j = 0; j < newSkeleton.bones.length; j++) {
-                if (newSkeleton.bones[j].id === id) {
-                    foundBone = true;
-                    break;
-                }
-            }
-            if (foundBone) {
-                continue;
-            }
             // Search for parent bone
+            var foundBone = false;
             var parentBone = null;
             for (var j = 0; j < i; j++) {
                 var joint = getJointNode(gltfRuntime, skins.jointNames[j]).node;
@@ -577,8 +565,8 @@ var BABYLON;
                 }
             }
         }
-        // Finish
         newSkeleton.prepare();
+        // Finish
         for (var i = 0; i < nodesToRootToAdd.length; i++) {
             newSkeleton.bones.push(nodesToRootToAdd[i]);
         }
@@ -775,7 +763,6 @@ var BABYLON;
                     }
                 }
                 if (newMesh.skeleton !== null) {
-                    newMesh.useBones = true;
                 }
                 lastNode = newMesh;
             }
@@ -960,7 +947,7 @@ var BABYLON;
                 }
                 if (type === BABYLON.EParameterType.SAMPLER_2D) {
                     var texture = gltfRuntime.textures[value].babylonTexture;
-                    if (texture === null) {
+                    if (texture === null || texture === undefined) {
                         continue;
                     }
                     shaderMaterial.getEffect().setTexture(unif, texture);
@@ -993,16 +980,18 @@ var BABYLON;
             if (!value) {
                 continue;
             }
-            var onLoadTexture = function (texture) {
-                if (uniform.value) {
-                    // Static uniform
-                    shaderMaterial.setTexture(unif, texture);
-                    delete unTreatedUniforms[unif];
-                }
+            var onLoadTexture = function (uniformName) {
+                return function (texture) {
+                    if (uniform.value) {
+                        // Static uniform
+                        shaderMaterial.setTexture(uniformName, texture);
+                        delete unTreatedUniforms[uniformName];
+                    }
+                };
             };
             // Texture (sampler2D)
             if (type === BABYLON.EParameterType.SAMPLER_2D) {
-                BABYLON.GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, value, onLoadTexture, function () { return onLoadTexture(null); });
+                BABYLON.GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, value, onLoadTexture(unif), function () { return onLoadTexture(null); });
             }
             else {
                 if (uniform.value && BABYLON.GLTFUtils.SetUniform(shaderMaterial, unif, value, type)) {

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/loaders/babylon.glTFFileLoader.min.js


+ 18 - 26
loaders/src/glTF/babylon.glTFFileLoader.ts

@@ -509,21 +509,10 @@ module BABYLON {
                 continue;
             }
 
-            // Check if node already exists
-            var foundBone = false;
-            for (var j = 0; j < newSkeleton.bones.length; j++) {
-                if (newSkeleton.bones[j].id === id) {
-                    foundBone = true;
-                    break;
-                }
-            }
-
-            if (foundBone) {
-                continue;
-            }
-
             // Search for parent bone
+            var foundBone = false;
             var parentBone: Bone = null;
+
             for (var j = 0; j < i; j++) {
                 var joint: IGLTFNode = getJointNode(gltfRuntime, skins.jointNames[j]).node;
 
@@ -564,6 +553,7 @@ module BABYLON {
             if (!parentBone && nodesToRoot.length === 0) {
                 var inverseBindMatrix = Matrix.FromArray(buffer, i * 16);
                 var invertMesh = Matrix.Invert(mesh.getWorldMatrix());
+
                 mat = mat.multiply(mesh.getWorldMatrix());
             }
 
@@ -574,7 +564,7 @@ module BABYLON {
         // Polish
         var bones = newSkeleton.bones;
         newSkeleton.bones = [];
-
+        
         for (var i = 0; i < skins.jointNames.length; i++) {
             var jointNode: IJointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
 
@@ -590,9 +580,9 @@ module BABYLON {
             }
         }
 
-        // Finish
         newSkeleton.prepare();
 
+        // Finish
         for (var i = 0; i < nodesToRootToAdd.length; i++) {
             newSkeleton.bones.push(nodesToRootToAdd[i]);
         }
@@ -834,7 +824,7 @@ module BABYLON {
                 }
 
                 if (newMesh.skeleton !== null) {
-                    newMesh.useBones = true;
+                    //newMesh.useBones = true;
                 }
 
                 lastNode = newMesh;
@@ -1059,7 +1049,7 @@ module BABYLON {
                 if (type === EParameterType.SAMPLER_2D) {
                     var texture: Texture = gltfRuntime.textures[value].babylonTexture;
 
-                    if (texture === null) {
+                    if (texture === null || texture === undefined) {
                         continue;
                     }
 
@@ -1089,27 +1079,29 @@ module BABYLON {
             var uniform: IGLTFTechniqueParameter = unTreatedUniforms[unif];
             var type = uniform.type;
             var value = materialValues[techniqueUniforms[unif]];
-            
+
             if (value === undefined) {
                 // In case the value is the same for all materials
-                value = <any> uniform.value;
+                value = <any>uniform.value;
             }
 
             if (!value) {
                 continue;
             }
 
-            var onLoadTexture = (texture: Texture) => {
-                if (uniform.value) {
-                    // Static uniform
-                    shaderMaterial.setTexture(unif, texture);
-                    delete unTreatedUniforms[unif];
+            var onLoadTexture = (uniformName: string) => {
+                return (texture: Texture) => {
+                    if (uniform.value) {
+                        // Static uniform
+                        shaderMaterial.setTexture(uniformName, texture);
+                        delete unTreatedUniforms[uniformName];
+                    }
                 }
             };
 
             // Texture (sampler2D)
             if (type === EParameterType.SAMPLER_2D) {
-                GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, <string>value, onLoadTexture, () => onLoadTexture(null));
+                GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, <string>value, onLoadTexture(unif), () => onLoadTexture(null));
             }
             // Others
             else {
@@ -1483,7 +1475,7 @@ module BABYLON {
                 attributes: attributes,
                 uniforms: uniforms,
                 samplers: samplers,
-                needAlphaBlending: states.functions && states.functions.blendEquationSeparate
+                needAlphaBlending: states.enable && states.enable.indexOf(3042) !== -1
             };
 
             Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;

+ 2 - 0
loaders/src/glTF/babylon.glTFFileLoaderInterfaces.ts

@@ -346,7 +346,9 @@ module BABYLON {
         animations: Object;
         skins: Object;
         currentScene: Object;
+
         extensionsUsed: string[];
+        extensionsRequired?: string[]; // v1.1
 
         buffersCount: number;
         shaderscount: number;

+ 3 - 3
src/Animations/babylon.animatable.ts

@@ -99,9 +99,9 @@
         }
 
         public stop(animationName?: string): void {
-            var index = this._scene._activeAnimatables.indexOf(this);
+            var idx = this._scene._activeAnimatables.indexOf(this);
 
-            if (index > -1) {
+            if (idx > -1) {
                 var animations = this._animations;
                 var numberOfAnimationsStopped = 0;
                 for (var index = animations.length - 1; index >= 0; index--) {
@@ -114,7 +114,7 @@
                 }
 
                 if (animations.length == numberOfAnimationsStopped) {
-                    this._scene._activeAnimatables.splice(index, 1);
+                    this._scene._activeAnimatables.splice(idx, 1);
 
                     if (this.onAnimationEnd) {
                         this.onAnimationEnd();

+ 2 - 1
src/Math/babylon.math.ts

@@ -239,6 +239,7 @@
         public static Magenta(): Color3 { return new Color3(1, 0, 1); }
         public static Yellow(): Color3 { return new Color3(1, 1, 0); }
         public static Gray(): Color3 { return new Color3(0.5, 0.5, 0.5); }
+        public static Random(): Color3 { return new Color3(Math.Random(), Math.Random(), Math.Random()); }
     }
 
     export class Color4 {
@@ -4081,4 +4082,4 @@
             Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero()];                      // 6 temp Matrices at once should be enough
     }
-}
+}