Browse Source

small fixes

David Catuhe 10 năm trước cách đây
mục cha
commit
8c8954dcb2

+ 4 - 1
Babylon/Audio/babylon.sound.js

@@ -96,8 +96,11 @@ var BABYLON;
                     BABYLON.Tools.Error("Web Audio is not supported by your browser.");
                     BABYLON.Engine.audioEngine.WarnedWebAudioUnsupported = true;
                 }
+                // Simulating a ready to play event to avoid breaking code for non web audio browsers
                 if (this._readyToPlayCallback) {
-                    this._readyToPlayCallback();
+                    window.setTimeout(function () {
+                        _this._readyToPlayCallback();
+                    }, 1000);
                 }
             }
         }

+ 4 - 1
Babylon/Audio/babylon.sound.ts

@@ -108,8 +108,11 @@
                     BABYLON.Tools.Error("Web Audio is not supported by your browser.");
                     Engine.audioEngine.WarnedWebAudioUnsupported = true;
                 }
+                // Simulating a ready to play event to avoid breaking code for non web audio browsers
                 if (this._readyToPlayCallback) {
-                    this._readyToPlayCallback();
+                    window.setTimeout(() => {
+                        this._readyToPlayCallback();
+                    }, 1000);
                 }
             }
         }

+ 1 - 1
Babylon/Materials/babylon.material.ts

@@ -105,7 +105,7 @@
             engine.setState(this.backFaceCulling, this.zOffset);
         }
 
-        public bind(world: Matrix, mesh: Mesh): void {
+        public bind(world: Matrix, mesh?: Mesh): void {
             this._scene._cachedMaterial = this;
 
             if (this.onBind) {

+ 25 - 3
Babylon/Materials/babylon.shaderMaterial.js

@@ -80,7 +80,7 @@ var BABYLON;
             this._matrices[name] = value;
             return this;
         };
-        ShaderMaterial.prototype.isReady = function () {
+        ShaderMaterial.prototype.isReady = function (mesh, useInstances) {
             var scene = this.getScene();
             var engine = scene.getEngine();
             if (!this.checkReadyOnEveryCall) {
@@ -88,8 +88,26 @@ var BABYLON;
                     return true;
                 }
             }
+            // Instances
+            var defines = [];
+            var fallbacks = new BABYLON.EffectFallbacks();
+            if (useInstances) {
+                defines.push("#define INSTANCES");
+            }
+            // Bones
+            if (mesh && mesh.useBones) {
+                defines.push("#define BONES");
+                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BONES4");
+                fallbacks.addFallback(0, "BONES4");
+            }
+            // Alpha test
+            if (engine.getAlphaTesting()) {
+                defines.push("#define ALPHATEST");
+            }
             var previousEffect = this._effect;
-            this._effect = engine.createEffect(this._shaderPath, this._options.attributes, this._options.uniforms, this._options.samplers, "", null, this.onCompiled, this.onError);
+            var join = defines.join("\n");
+            this._effect = engine.createEffect(this._shaderPath, this._options.attributes, this._options.uniforms, this._options.samplers, join, fallbacks, this.onCompiled, this.onError);
             if (!this._effect.isReady()) {
                 return false;
             }
@@ -112,7 +130,7 @@ var BABYLON;
                 this._effect.setMatrix("worldViewProjection", world.multiply(scene.getTransformMatrix()));
             }
         };
-        ShaderMaterial.prototype.bind = function (world) {
+        ShaderMaterial.prototype.bind = function (world, mesh) {
             // Std values
             this.bindOnlyWorldMatrix(world);
             if (this.getScene().getCachedMaterial() !== this) {
@@ -125,6 +143,10 @@ var BABYLON;
                 if (this._options.uniforms.indexOf("viewProjection") !== -1) {
                     this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
                 }
+                // Bones
+                if (mesh.useBones) {
+                    this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
+                }
                 for (var name in this._textures) {
                     this._effect.setTexture(name, this._textures[name]);
                 }

+ 30 - 3
Babylon/Materials/babylon.shaderMaterial.ts

@@ -98,7 +98,7 @@
             return this;
         }
 
-        public isReady(): boolean {
+        public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
             var scene = this.getScene();
             var engine = scene.getEngine();
 
@@ -108,12 +108,34 @@
                 }
             }
 
+            // Instances
+            var defines = [];
+            var fallbacks = new EffectFallbacks();
+            if (useInstances) {
+                defines.push("#define INSTANCES");
+            }
+
+            // Bones
+            if (mesh && mesh.useBones) {
+                defines.push("#define BONES");
+                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+                defines.push("#define BONES4");
+                fallbacks.addFallback(0, "BONES4");
+            }
+
+            // Alpha test
+            if (engine.getAlphaTesting()) {
+                defines.push("#define ALPHATEST");
+            }
+
             var previousEffect = this._effect;
+            var join = defines.join("\n");
+
             this._effect = engine.createEffect(this._shaderPath,
                 this._options.attributes,
                 this._options.uniforms,
                 this._options.samplers,
-                "", null, this.onCompiled, this.onError);
+                join, fallbacks, this.onCompiled, this.onError);
 
             if (!this._effect.isReady()) {
                 return false;
@@ -145,7 +167,7 @@
             }
         }
 
-        public bind(world: Matrix): void {
+        public bind(world: Matrix, mesh?: Mesh): void {
             // Std values
             this.bindOnlyWorldMatrix(world);
 
@@ -162,6 +184,11 @@
                     this._effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
                 }
 
+                // Bones
+                if (mesh.useBones) {
+                    this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
+                }
+
                 // Texture
                 for (var name in this._textures) {
                     this._effect.setTexture(name, this._textures[name]);

+ 1 - 1
Babylon/Materials/babylon.standardMaterial.js

@@ -351,7 +351,7 @@ var BABYLON;
             this.bindOnlyWorldMatrix(world);
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            if (mesh.useBones) {
+            if (mesh && mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
             if (scene.getCachedMaterial() !== this) {

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

@@ -425,7 +425,7 @@
             this._effect.setMatrix("world", world);
         }
 
-        public bind(world: Matrix, mesh: Mesh): void {
+        public bind(world: Matrix, mesh?: Mesh): void {
             var scene = this.getScene();
 
             // Matrices        
@@ -433,7 +433,7 @@
             this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            if (mesh.useBones) {
+            if (mesh && mesh.useBones) {
                 this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
             }
 

+ 27 - 16
Babylon/Math/babylon.math.js

@@ -2625,7 +2625,33 @@ var BABYLON;
             this._tangents = new Array();
             this._normals = new Array();
             this._binormals = new Array();
-            this._curve = path.slice(); // copy array         
+            this._curve = path.slice(); // copy array  
+            this._compute();
+        }
+        Path3D.prototype.getCurve = function () {
+            return this._curve;
+        };
+        Path3D.prototype.getTangents = function () {
+            return this._tangents;
+        };
+        Path3D.prototype.getNormals = function () {
+            return this._normals;
+        };
+        Path3D.prototype.getBinormals = function () {
+            return this._binormals;
+        };
+        Path3D.prototype.getDistances = function () {
+            return this._distances;
+        };
+        Path3D.prototype.update = function (path) {
+            for (var i = 0; i < path.length; i++) {
+                this._curve[i] = path[i];
+            }
+            this._compute();
+            return this;
+        };
+        // private function compute() : computes tangents, normals and binormals
+        Path3D.prototype._compute = function () {
             var l = this._curve.length;
             // first and last tangents
             this._tangents[0] = this._curve[1].subtract(this._curve[0]);
@@ -2665,21 +2691,6 @@ var BABYLON;
                 this._binormals[i] = Vector3.Cross(curTang, this._normals[i]);
                 this._binormals[i].normalize();
             }
-        }
-        Path3D.prototype.getCurve = function () {
-            return this._curve;
-        };
-        Path3D.prototype.getTangents = function () {
-            return this._tangents;
-        };
-        Path3D.prototype.getNormals = function () {
-            return this._normals;
-        };
-        Path3D.prototype.getBinormals = function () {
-            return this._binormals;
-        };
-        Path3D.prototype.getDistances = function () {
-            return this._distances;
         };
         // private function normalVector(v0, vt) :
         // returns an arbitrary point in the plane defined by the point v0 and the vector vt orthogonal to this plane

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 108 - 69
babylon.2.1-alpha.debug.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 9 - 9
babylon.2.1-alpha.js