Browse Source

Fixed issue with sprites
Added onDispose at node level

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

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 23 - 23
dist/preview release/babylon.core.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2784 - 2778
dist/preview release/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 34 - 34
dist/preview release/babylon.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 90 - 25
dist/preview release/babylon.max.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 33 - 33
dist/preview release/babylon.noworker.js


+ 4 - 0
src/Animations/babylon.animation.js

@@ -462,6 +462,10 @@ var BABYLON;
             if (to < this._keys[0].frame || to > this._keys[this._keys.length - 1].frame) {
                 to = this._keys[this._keys.length - 1].frame;
             }
+            //to and from cannot be the same key
+            if (from === to) {
+                from++;
+            }
             // Compute ratio
             var range = to - from;
             var offsetValue;

+ 32 - 5
src/Bones/babylon.bone.js

@@ -305,6 +305,19 @@ var BABYLON;
             rotMatInv.multiplyToRef(rotMat, rotMat);
             this._rotateWithMatrix(rotMat, space, mesh);
         };
+        Bone.prototype.setRotation = function (rotation, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            this.setYawPitchRoll(rotation.y, rotation.x, rotation.z, space, mesh);
+        };
+        Bone.prototype.setRotationQuaternion = function (quat, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            var rotMatInv = BABYLON.Tmp.Matrix[0];
+            this._getNegativeRotationToRef(rotMatInv, space, mesh);
+            var rotMat = BABYLON.Tmp.Matrix[1];
+            BABYLON.Matrix.FromQuaternionToRef(quat, rotMat);
+            rotMatInv.multiplyToRef(rotMat, rotMat);
+            this._rotateWithMatrix(rotMat, space, mesh);
+        };
         Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var rotMatInv = BABYLON.Tmp.Matrix[0];
@@ -471,12 +484,24 @@ var BABYLON;
         };
         Bone.prototype.getRotation = function (space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            var result = BABYLON.Quaternion.Identity();
+            var result = BABYLON.Vector3.Zero();
             this.getRotationToRef(space, mesh, result);
             return result;
         };
         Bone.prototype.getRotationToRef = function (space, mesh, result) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            var quat = BABYLON.Tmp.Quaternion[0];
+            this.getRotationQuaternionToRef(space, mesh, quat);
+            quat.toEulerAnglesToRef(result);
+        };
+        Bone.prototype.getRotationQuaternion = function (space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            var result = BABYLON.Quaternion.Identity();
+            this.getRotationQuaternionToRef(space, mesh, result);
+            return result;
+        };
+        Bone.prototype.getRotationQuaternionToRef = function (space, mesh, result) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space == BABYLON.Space.LOCAL) {
                 this.getLocalMatrix().decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
             }
@@ -484,13 +509,15 @@ var BABYLON;
                 var mat = BABYLON.Tmp.Matrix[0];
                 var amat = this.getAbsoluteTransform();
                 if (mesh) {
-                    var wmat = mesh.getWorldMatrix();
-                    amat.multiplyToRef(wmat, mat);
-                    mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                    amat.multiplyToRef(mesh.getWorldMatrix(), mat);
                 }
                 else {
-                    amat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                    mat.copyFrom(amat);
                 }
+                mat.m[0] *= this._scalingDeterminant;
+                mat.m[1] *= this._scalingDeterminant;
+                mat.m[2] *= this._scalingDeterminant;
+                mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
             }
         };
         return Bone;

+ 6 - 0
src/Lights/babylon.spotLight.js

@@ -80,6 +80,12 @@ var BABYLON;
         SpotLight.prototype.getTypeID = function () {
             return 2;
         };
+        SpotLight.prototype.getRotation = function () {
+            this.direction.normalize();
+            var xaxis = BABYLON.Vector3.Cross(this.direction, BABYLON.Axis.Y);
+            var yaxis = BABYLON.Vector3.Cross(xaxis, this.direction);
+            return BABYLON.Vector3.RotationFromAxis(xaxis, yaxis, this.direction);
+        };
         __decorate([
             BABYLON.serializeAsVector3()
         ], SpotLight.prototype, "position", void 0);

+ 27 - 0
src/Math/babylon.math.js

@@ -2498,6 +2498,33 @@ var BABYLON;
             mat.m[14] = 0;
             mat.m[15] = 1;
         };
+        Matrix.FromQuaternionToRef = function (quat, result) {
+            var xx = quat.x * quat.x;
+            var yy = quat.y * quat.y;
+            var zz = quat.z * quat.z;
+            var xy = quat.x * quat.y;
+            var zw = quat.z * quat.w;
+            var zx = quat.z * quat.x;
+            var yw = quat.y * quat.w;
+            var yz = quat.y * quat.z;
+            var xw = quat.x * quat.w;
+            result.m[0] = 1.0 - (2.0 * (yy + zz));
+            result.m[1] = 2.0 * (xy + zw);
+            result.m[2] = 2.0 * (zx - yw);
+            result.m[3] = 0;
+            result.m[4] = 2.0 * (xy - zw);
+            result.m[5] = 1.0 - (2.0 * (zz + xx));
+            result.m[6] = 2.0 * (yz + xw);
+            result.m[7] = 0;
+            result.m[8] = 2.0 * (zx + yw);
+            result.m[9] = 2.0 * (yz - xw);
+            result.m[10] = 1.0 - (2.0 * (yy + xx));
+            result.m[11] = 0;
+            result.m[12] = 0;
+            result.m[13] = 0;
+            result.m[14] = 0;
+            result.m[15] = 1.0;
+        };
         Matrix._tempQuaternion = new Quaternion();
         Matrix._xAxis = Vector3.Zero();
         Matrix._yAxis = Vector3.Zero();

+ 1 - 19
src/Mesh/babylon.abstractMesh.js

@@ -13,11 +13,6 @@ var BABYLON;
             _super.call(this, name, scene);
             // Events
             /**
-            * An event triggered when the mesh is disposed.
-            * @type {BABYLON.Observable}
-            */
-            this.onDisposeObservable = new BABYLON.Observable();
-            /**
             * An event triggered when this mesh collides with another one
             * @type {BABYLON.Observable}
             */
@@ -141,16 +136,6 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
-        Object.defineProperty(AbstractMesh.prototype, "onDispose", {
-            set: function (callback) {
-                if (this._onDisposeObserver) {
-                    this.onDisposeObservable.remove(this._onDisposeObserver);
-                }
-                this._onDisposeObserver = this.onDisposeObservable.add(callback);
-            },
-            enumerable: true,
-            configurable: true
-        });
         Object.defineProperty(AbstractMesh.prototype, "onCollide", {
             set: function (callback) {
                 if (this._onCollideObserver) {
@@ -1039,14 +1024,11 @@ var BABYLON;
                     child.computeWorldMatrix(true);
                 }
             }
-            _super.prototype.dispose.call(this);
             this.onAfterWorldMatrixUpdateObservable.clear();
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
             this._isDisposed = true;
-            // Callback
-            this.onDisposeObservable.notifyObservers(this);
-            this.onDisposeObservable.clear();
+            _super.prototype.dispose.call(this);
         };
         // Statics
         AbstractMesh._BILLBOARDMODE_NONE = 0;

+ 1 - 19
src/Mesh/babylon.abstractMesh.ts

@@ -30,20 +30,6 @@
         // Events
 
         /**
-        * An event triggered when the mesh is disposed.
-        * @type {BABYLON.Observable}
-        */
-        public onDisposeObservable = new Observable<AbstractMesh>();
-
-        private _onDisposeObserver: Observer<AbstractMesh>;
-        public set onDispose(callback: () => void) {
-            if (this._onDisposeObserver) {
-                this.onDisposeObservable.remove(this._onDisposeObserver);
-            }
-            this._onDisposeObserver = this.onDisposeObservable.add(callback);
-        }
-
-        /**
         * An event triggered when this mesh collides with another one
         * @type {BABYLON.Observable}
         */
@@ -1212,17 +1198,13 @@
                 }
             }
 
-            super.dispose();
-
             this.onAfterWorldMatrixUpdateObservable.clear();
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
 
             this._isDisposed = true;
 
-            // Callback
-            this.onDisposeObservable.notifyObservers(this);
-            this.onDisposeObservable.clear();
+            super.dispose();
         }
     }
 }

+ 1 - 0
src/Sprites/babylon.spriteManager.js

@@ -31,6 +31,7 @@ var BABYLON;
             else {
                 return;
             }
+            this._epsilon = epsilon;
             this._scene = scene;
             this._scene.spriteManagers.push(this);
             var indices = [];

+ 1 - 0
src/Sprites/babylon.spriteManager.ts

@@ -59,6 +59,7 @@
                return;   
             }
 
+            this._epsilon = epsilon;
             this._scene = scene;
             this._scene.spriteManagers.push(this);
 

+ 18 - 0
src/babylon.node.js

@@ -25,6 +25,11 @@ var BABYLON;
             this._isReady = true;
             this._currentRenderId = -1;
             this._parentRenderId = -1;
+            /**
+            * An event triggered when the mesh is disposed.
+            * @type {BABYLON.Observable}
+            */
+            this.onDisposeObservable = new BABYLON.Observable();
             this.name = name;
             this.id = name;
             this._scene = scene;
@@ -55,6 +60,16 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Node.prototype, "onDispose", {
+            set: function (callback) {
+                if (this._onDisposeObserver) {
+                    this.onDisposeObservable.remove(this._onDisposeObserver);
+                }
+                this._onDisposeObserver = this.onDisposeObservable.add(callback);
+            },
+            enumerable: true,
+            configurable: true
+        });
         Node.prototype.getScene = function () {
             return this._scene;
         };
@@ -272,6 +287,9 @@ var BABYLON;
         };
         Node.prototype.dispose = function () {
             this.parent = null;
+            // Callback
+            this.onDisposeObservable.notifyObservers(this);
+            this.onDisposeObservable.clear();
         };
         Node.prototype.getDirection = function (localAxis) {
             var result = BABYLON.Vector3.Zero();

+ 18 - 0
src/babylon.node.ts

@@ -65,6 +65,20 @@
         }
 
         /**
+        * An event triggered when the mesh is disposed.
+        * @type {BABYLON.Observable}
+        */
+        public onDisposeObservable = new Observable<Node>();
+
+        private _onDisposeObserver: Observer<Node>;
+        public set onDispose(callback: () => void) {
+            if (this._onDisposeObserver) {
+                this.onDisposeObservable.remove(this._onDisposeObserver);
+            }
+            this._onDisposeObserver = this.onDisposeObservable.add(callback);
+        }
+
+        /**
          * @constructor
          * @param {string} name - the name and id to be given to this node
          * @param {BABYLON.Scene} the scene this node will be added to
@@ -341,6 +355,10 @@
 
         public dispose(): void {
             this.parent = null;
+
+            // Callback
+            this.onDisposeObservable.notifyObservers(this);
+            this.onDisposeObservable.clear();
         }
 
         public getDirection(localAxis:BABYLON.Vector3): BABYLON.Vector3 {