Explorar o código

Merge pull request #2344 from bghgary/misc-fixes

Misc fixes
David Catuhe %!s(int64=8) %!d(string=hai) anos
pai
achega
34d64403cc

+ 41 - 21
src/Bones/babylon.bone.ts

@@ -21,50 +21,68 @@ module BABYLON {
         private _parent: Bone;
 
         private _scaleMatrix = Matrix.Identity();
-        private _scaleVector = new Vector3(1, 1, 1);
-        private _negateScaleChildren = new Vector3(1, 1, 1);
+        private _scaleVector = Vector3.One();
+        private _negateScaleChildren = Vector3.One();
         private _scalingDeterminant = 1;
 
-        get _matrix():Matrix{
+        get _matrix(): Matrix {
             return this._localMatrix;
         }
 
-        set _matrix(val:Matrix){
-            if(this._localMatrix){
+        set _matrix(val: Matrix) {
+            if (this._localMatrix) {
                 this._localMatrix.copyFrom(val);
-            }else{
+            } else {
                 this._localMatrix = val;
             }
         }
-        
-        constructor(public name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix, restPose?: Matrix) {
+
+        constructor(public name: string, skeleton: Skeleton, parentBone: Bone = null, matrix?: Matrix, restPose?: Matrix) {
             super(name, skeleton.getScene());
             this._skeleton = skeleton;
-            this._localMatrix = matrix;
-            this._baseMatrix = matrix.clone();
-            this._restPose = restPose ? restPose : matrix.clone();
+            this._localMatrix = matrix ? matrix : Matrix.Identity();
+            this._baseMatrix = this._localMatrix.clone();
+            this._restPose = restPose ? restPose : this._localMatrix.clone();
 
             skeleton.bones.push(this);
 
-            if (parentBone) {
-                this._parent = parentBone;
-                parentBone.children.push(this);
-            } else {
-                this._parent = null;
-            }
+            this.setParent(parentBone, false);
 
             this._updateDifferenceMatrix();
-
-            if (this.getAbsoluteTransform().determinant() < 0) {
-                this._scalingDeterminant *= -1;
-            }
         }
 
         // Members
+        public getSkeleton(): Skeleton {
+            return this._skeleton;
+        }
+
         public getParent(): Bone {
             return this._parent;
         }
 
+        public setParent(parent: Bone, updateDifferenceMatrix: boolean = true): void {
+            if (this._parent === parent) {
+                return;
+            }
+
+            if (this._parent) {
+                var index = this._parent.children.indexOf(this);
+                if (index !== -1) {
+                    this._parent.children.splice(index);
+                }
+            }
+
+            this._parent = parent;
+
+            if (this._parent) {
+                this._parent.children.push(this);
+            }
+
+            if (updateDifferenceMatrix) {
+                this._updateDifferenceMatrix();
+            }
+        }
+
         public getLocalMatrix(): Matrix {
             return this._localMatrix;
         }
@@ -154,6 +172,8 @@ module BABYLON {
             for (var index = 0; index < this.children.length; index++) {
                 this.children[index]._updateDifferenceMatrix();
             }
+
+            this._scalingDeterminant = (this._absoluteTransform.determinant() < 0 ? -1 : 1);
         }
 
         public markAsDirty(): void {

+ 1 - 1
src/Collisions/babylon.collider.ts

@@ -58,7 +58,7 @@
     )();
 
     export class Collider {
-        public radius = new Vector3(1, 1, 1);
+        public radius = Vector3.One();
         public retry = 0;
         public velocity: Vector3;
         public basePoint: Vector3;

+ 20 - 5
src/Materials/Textures/babylon.texture.ts

@@ -96,11 +96,6 @@
             this._format = format;
 
             scene = this.getScene();
-            if (!url) {
-                return;
-            }
-
-            this._texture = this._getFromCache(url, noMipmap, samplingMode);
 
             let load = () => {
                 if (this._onLoadObservarble && this._onLoadObservarble.hasObservers()) {
@@ -115,6 +110,14 @@
                 }
             }
 
+            if (!url) {
+                this._delayedOnLoad = load;
+                this._delayedOnError = onError;
+                return;
+            }
+
+            this._texture = this._getFromCache(url, noMipmap, samplingMode);
+
             if (!this._texture) {
                 if (!scene.useDelayedTextureLoading) {
                     this._texture = scene.getEngine().createTexture(url, noMipmap, invertY, scene, this._samplingMode, load, onError, this._buffer, null, this._format);
@@ -136,6 +139,12 @@
             }
         }
 
+        public updateURL(url: string): void {
+            this.url = url;
+            this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
+            this.delayLoad();
+        }
+
         public delayLoad(): void {
             if (this.delayLoadState !== Engine.DELAYLOADSTATE_NOTLOADED) {
                 return;
@@ -149,6 +158,12 @@
                 if (this._deleteBuffer) {
                     delete this._buffer;
                 }
+            } else {
+                if (this._texture.isReady) {
+                    Tools.SetImmediate(() => this._delayedOnLoad());
+                } else {
+                    this._texture.onLoadedCallbacks.push(this._delayedOnLoad);
+                }
             }
         }
 

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

@@ -874,6 +874,12 @@
             return new Vector2(0, 0);
         }
         /**
+         * Returns a new Vector2(1, 1)
+         */
+        public static One(): Vector2 {
+            return new Vector2(1, 1);
+        }
+        /**
          * Returns a new Vector2 set from the passed index element of the passed array.
          */
         public static FromArray(array: ArrayLike<number>, offset: number = 0): Vector2 {
@@ -1463,12 +1469,18 @@
         }
 
         /**
-         * Returns a new Vector3 set to (0.0, 0.0, 0.0).  
+         * Returns a new Vector3 set to (0.0, 0.0, 0.0).
          */
         public static Zero(): Vector3 {
             return new Vector3(0.0, 0.0, 0.0);
         }
         /**
+         * Returns a new Vector3 set to (1.0, 1.0, 1.0).
+         */
+        public static One(): Vector3 {
+            return new Vector3(1.0, 1.0, 1.0);
+        }
+        /**
          * Returns a new Vector3 set to (0.0, 1.0, 0.0)
          */
         public static Up(): Vector3 {
@@ -2200,6 +2212,12 @@
             return new Vector4(0.0, 0.0, 0.0, 0.0);
         }
         /**
+         * Returns a new Vector4 set to (1.0, 1.0, 1.0, 1.0)
+         */
+        public static One(): Vector4 {
+            return new Vector4(1.0, 1.0, 1.0, 1.0);
+        }
+        /**
          * Returns a new normalized Vector4 from the passed one.  
          */
         public static Normalize(vector: Vector4): Vector4 {

+ 3 - 3
src/Mesh/babylon.abstractMesh.ts

@@ -114,10 +114,10 @@
 
         // Properties
         public definedFacingForward = true; // orientation for POV movement & rotation
-        public position = new Vector3(0.0, 0.0, 0.0);
-        private _rotation = new Vector3(0.0, 0.0, 0.0);
+        public position = Vector3.Zero();
+        private _rotation = Vector3.Zero();
         private _rotationQuaternion: Quaternion;
-        private _scaling = new Vector3(1.0, 1.0, 1.0);
+        private _scaling = Vector3.One();
         public billboardMode = AbstractMesh.BILLBOARDMODE_NONE;
         public visibility = 1.0;
         public alphaIndex = Number.MAX_VALUE;

+ 1 - 1
src/Mesh/babylon.meshBuilder.ts

@@ -1005,7 +1005,7 @@
             var normals = sourceMesh.getVerticesData(VertexBuffer.NormalKind);
             var position = options.position || Vector3.Zero();
             var normal = options.normal || Vector3.Up();
-            var size = options.size || new Vector3(1, 1, 1);
+            var size = options.size || Vector3.One();
             var angle = options.angle || 0;
 
             // Getting correct rotation

+ 1 - 1
src/Particles/babylon.solidParticle.ts

@@ -6,7 +6,7 @@ module BABYLON {
         public position = Vector3.Zero();               // position
         public rotation = Vector3.Zero();               // rotation
         public rotationQuaternion: Quaternion;          // quaternion, will overwrite rotation
-        public scaling = new Vector3(1.0, 1.0, 1.0);    // scaling
+        public scaling = Vector3.One();                 // scaling
         public uvs = new Vector4(0.0, 0.0, 1.0, 1.0);   // uvs
         public velocity = Vector3.Zero();               // velocity
         public alive = true;                            // alive