Explorar el Código

Fixing billboards

David Catuhe hace 10 años
padre
commit
a486d41c1f

+ 2 - 4
Babylon/Cameras/babylon.camera.js

@@ -240,9 +240,9 @@ var BABYLON;
             }
             this._computedViewMatrix.invertToRef(this._worldMatrix);
             this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
+            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
             this._computedViewMatrix.invert();
             this._currentRenderId = this.getScene().getRenderId();
-            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
             return this._computedViewMatrix;
         };
         Camera.prototype._computeViewMatrix = function (force) {
@@ -250,9 +250,7 @@ var BABYLON;
                 return this._computedViewMatrix;
             }
             this._computedViewMatrix = this._getViewMatrix();
-            if (!this.parent || !this.parent.getWorldMatrix) {
-                this._currentRenderId = this.getScene().getRenderId();
-            }
+            this._currentRenderId = this.getScene().getRenderId();
             return this._computedViewMatrix;
         };
         Camera.prototype.getProjectionMatrix = function (force) {

+ 4 - 5
Babylon/Cameras/babylon.camera.ts

@@ -10,7 +10,7 @@
         public static get PERSPECTIVE_CAMERA(): number {
             return Camera._PERSPECTIVE_CAMERA;
         }
-        
+
         public static get ORTHOGRAPHIC_CAMERA(): number {
             return Camera._ORTHOGRAPHIC_CAMERA;
         }
@@ -304,11 +304,11 @@
             this._computedViewMatrix.invertToRef(this._worldMatrix);
 
             this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
+            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
 
             this._computedViewMatrix.invert();
 
             this._currentRenderId = this.getScene().getRenderId();
-            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
 
             return this._computedViewMatrix;
         }
@@ -319,9 +319,8 @@
             }
 
             this._computedViewMatrix = this._getViewMatrix();
-            if (!this.parent || !this.parent.getWorldMatrix) {
-                this._currentRenderId = this.getScene().getRenderId();
-            }
+            this._currentRenderId = this.getScene().getRenderId();
+
             return this._computedViewMatrix;
         }
 

+ 14 - 5
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -687,9 +687,9 @@ var BABYLON;
                     target = target[effectiveTarget[i]];
                 }
                 // Return appropriate value with its type
-                if (target instanceof Boolean)
+                if (typeof (target) === "boolean")
                     return values[0] === "true";
-                if (target instanceof String)
+                if (typeof (target) === "string")
                     return values[0];
                 // Parameters with multiple values such as Vector3 etc.
                 var split = new Array();
@@ -730,8 +730,12 @@ var BABYLON;
                     for (var i = 0; i < parsedAction.properties.length; i++) {
                         var value = parsedAction.properties[i].value;
                         var name = parsedAction.properties[i].name;
+                        var targetType = parsedAction.properties[i].targetType;
                         if (name === "target")
-                            value = target = scene.getNodeByName(value);
+                            if (targetType != null && targetType === "SceneProperties")
+                                value = target = scene;
+                            else
+                                value = target = scene.getNodeByName(value);
                         else if (name === "parent")
                             value = scene.getNodeByName(value);
                         else if (name === "sound")
@@ -748,7 +752,12 @@ var BABYLON;
                         parameters.push(value);
                     }
                 }
-                parameters.push(condition);
+                if (combineArray === null) {
+                    parameters.push(condition);
+                }
+                else {
+                    parameters.push(null);
+                }
                 // If interpolate value action
                 if (parsedAction.name === "InterpolateValueAction") {
                     var param = parameters[parameters.length - 2];
@@ -781,7 +790,7 @@ var BABYLON;
                 var trigger = parsedActions.children[i];
                 if (trigger.properties.length > 0) {
                     var param = trigger.properties[0].value;
-                    var value = trigger.properties[0].targetType == null ? param : scene.getMeshByName(param);
+                    var value = trigger.properties[0].targetType === null ? param : scene.getMeshByName(param);
                     triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: value };
                 }
                 else

+ 15 - 5
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -862,10 +862,10 @@
             }
 
             // Return appropriate value with its type
-            if (target instanceof Boolean)
+            if (typeof (target) === "boolean")
                 return values[0] === "true";
 
-            if (target instanceof String)
+            if (typeof (target) === "string")
                 return values[0];
 
             // Parameters with multiple values such as Vector3 etc.
@@ -915,9 +915,13 @@
                 for (var i = 0; i < parsedAction.properties.length; i++) {
                     var value = parsedAction.properties[i].value;
                     var name = parsedAction.properties[i].name;
+                    var targetType = parsedAction.properties[i].targetType;
 
                     if (name === "target")
-                        value = target = scene.getNodeByName(value);
+                        if (targetType != null && targetType === "SceneProperties")
+                            value = target = scene;
+                        else
+                            value = target = scene.getNodeByName(value);
                     else if (name === "parent")
                         value = scene.getNodeByName(value);
                     else if (name === "sound")
@@ -934,7 +938,13 @@
                     parameters.push(value);
                 }
             }
-            parameters.push(condition);
+
+            if (combineArray === null) {
+                parameters.push(condition);
+            }
+            else {
+                parameters.push(null);
+            }
 
             // If interpolate value action
             if (parsedAction.name === "InterpolateValueAction") {
@@ -972,7 +982,7 @@
 
             if (trigger.properties.length > 0) {
                 var param = trigger.properties[0].value;
-                var value = trigger.properties[0].targetType == null ? param : scene.getMeshByName(param);
+                var value = trigger.properties[0].targetType === null ? param : scene.getMeshByName(param);
                 triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: value };
             }
             else

+ 2 - 5
Babylon/Mesh/babylon.abstractMesh.js

@@ -387,15 +387,12 @@ var BABYLON;
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
-                var zero = this.getScene().activeCamera.position.clone();
+                var zero = this.getScene().activeCamera.globalPosition.clone();
                 if (this.parent && this.parent.position) {
                     localPosition.addInPlace(this.parent.position);
                     BABYLON.Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, this._localTranslation);
                 }
-                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) === AbstractMesh.BILLBOARDMODE_ALL) {
-                    zero = this.getScene().activeCamera.position;
-                }
-                else {
+                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) != AbstractMesh.BILLBOARDMODE_ALL) {
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_X)
                         zero.x = localPosition.x + BABYLON.Engine.Epsilon;
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_Y)

+ 2 - 4
Babylon/Mesh/babylon.abstractMesh.ts

@@ -435,16 +435,14 @@
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
-                var zero = this.getScene().activeCamera.position.clone();
+                var zero = this.getScene().activeCamera.globalPosition.clone();
 
                 if (this.parent && (<any>this.parent).position) {
                     localPosition.addInPlace((<any>this.parent).position);
                     Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, this._localTranslation);
                 }
 
-                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) === AbstractMesh.BILLBOARDMODE_ALL) {
-                    zero = this.getScene().activeCamera.position;
-                } else {
+                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) != AbstractMesh.BILLBOARDMODE_ALL) {
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_X)
                         zero.x = localPosition.x + Engine.Epsilon;
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_Y)

+ 5 - 5
Babylon/babylon.engine.js

@@ -295,6 +295,11 @@ var BABYLON;
         var potHeight = BABYLON.Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
         gl.bindTexture(gl.TEXTURE_2D, texture);
         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
+        texture._baseWidth = width;
+        texture._baseHeight = height;
+        texture._width = potWidth;
+        texture._height = potHeight;
+        texture.isReady = true;
         processFunction(potWidth, potHeight);
         var filters = getSamplingParameters(samplingMode, !noMipmap, gl);
         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
@@ -304,11 +309,6 @@ var BABYLON;
         }
         gl.bindTexture(gl.TEXTURE_2D, null);
         engine._activeTexturesCache = [];
-        texture._baseWidth = width;
-        texture._baseHeight = height;
-        texture._width = potWidth;
-        texture._height = potHeight;
-        texture.isReady = true;
         texture.samplingMode = samplingMode;
         scene._removePendingData(texture);
     };

+ 1 - 1
Babylon/babylon.engine.ts

@@ -2258,4 +2258,4 @@
             }
         }
     }
-}
+}

+ 15 - 0
Babylon/babylon.scene.js

@@ -563,6 +563,21 @@ var BABYLON;
                 // Remove from the scene if mesh found 
                 this.cameras.splice(index, 1);
             }
+            // Remove from activeCameras
+            var index2 = this.activeCameras.indexOf(toRemove);
+            if (index2 !== -1) {
+                // Remove from the scene if mesh found
+                this.activeCameras.splice(index2, 1);
+            }
+            // Reset the activeCamera
+            if (this.activeCamera === toRemove) {
+                if (this.cameras.length > 0) {
+                    this.activeCamera = this.cameras[0];
+                }
+                else {
+                    this.activeCamera = null;
+                }
+            }
             if (this.onCameraRemoved) {
                 this.onCameraRemoved(toRemove);
             }

+ 6 - 2
Babylon/babylon.scene.ts

@@ -768,7 +768,11 @@
             }
             // Reset the activeCamera
             if (this.activeCamera === toRemove) {
-                this.activeCamera = null;
+                if (this.cameras.length > 0) {
+                    this.activeCamera = this.cameras[0];
+                } else {
+                    this.activeCamera = null;
+                }
             }
             if (this.onCameraRemoved) {
                 this.onCameraRemoved(toRemove);
@@ -2170,4 +2174,4 @@
             return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         }
     }
-} 
+} 

+ 40 - 19
babylon.2.1-alpha.debug.js

@@ -3954,6 +3954,11 @@ var __extends = this.__extends || function (d, b) {
         var potHeight = BABYLON.Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
         gl.bindTexture(gl.TEXTURE_2D, texture);
         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
+        texture._baseWidth = width;
+        texture._baseHeight = height;
+        texture._width = potWidth;
+        texture._height = potHeight;
+        texture.isReady = true;
         processFunction(potWidth, potHeight);
         var filters = getSamplingParameters(samplingMode, !noMipmap, gl);
         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
@@ -3963,11 +3968,6 @@ var __extends = this.__extends || function (d, b) {
         }
         gl.bindTexture(gl.TEXTURE_2D, null);
         engine._activeTexturesCache = [];
-        texture._baseWidth = width;
-        texture._baseHeight = height;
-        texture._width = potWidth;
-        texture._height = potHeight;
-        texture.isReady = true;
         texture.samplingMode = samplingMode;
         scene._removePendingData(texture);
     };
@@ -7141,9 +7141,9 @@ var BABYLON;
             }
             this._computedViewMatrix.invertToRef(this._worldMatrix);
             this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
+            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
             this._computedViewMatrix.invert();
             this._currentRenderId = this.getScene().getRenderId();
-            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
             return this._computedViewMatrix;
         };
         Camera.prototype._computeViewMatrix = function (force) {
@@ -7151,9 +7151,9 @@ var BABYLON;
                 return this._computedViewMatrix;
             }
             this._computedViewMatrix = this._getViewMatrix();
-            if (!this.parent || !this.parent.getWorldMatrix) {
-                this._currentRenderId = this.getScene().getRenderId();
-            }
+            // if (!this.parent || !this.parent.getWorldMatrix) {
+            this._currentRenderId = this.getScene().getRenderId();
+            //}
             return this._computedViewMatrix;
         };
         Camera.prototype.getProjectionMatrix = function (force) {
@@ -8742,6 +8742,21 @@ var BABYLON;
                 // Remove from the scene if mesh found 
                 this.cameras.splice(index, 1);
             }
+            // Remove from activeCameras
+            var index2 = this.activeCameras.indexOf(toRemove);
+            if (index2 !== -1) {
+                // Remove from the scene if mesh found
+                this.activeCameras.splice(index2, 1);
+            }
+            // Reset the activeCamera
+            if (this.activeCamera === toRemove) {
+                if (this.cameras.length > 0) {
+                    this.activeCamera = this.cameras[0];
+                }
+                else {
+                    this.activeCamera = null;
+                }
+            }
             if (this.onCameraRemoved) {
                 this.onCameraRemoved(toRemove);
             }
@@ -10432,15 +10447,12 @@ var BABYLON;
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
                 var localPosition = this.position.clone();
-                var zero = this.getScene().activeCamera.position.clone();
+                var zero = this.getScene().activeCamera.globalPosition.clone();
                 if (this.parent && this.parent.position) {
                     localPosition.addInPlace(this.parent.position);
                     BABYLON.Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, this._localTranslation);
                 }
-                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) === AbstractMesh.BILLBOARDMODE_ALL) {
-                    zero = this.getScene().activeCamera.position;
-                }
-                else {
+                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) != AbstractMesh.BILLBOARDMODE_ALL) {
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_X)
                         zero.x = localPosition.x + BABYLON.Engine.Epsilon;
                     if (this.billboardMode & AbstractMesh.BILLBOARDMODE_Y)
@@ -20358,9 +20370,9 @@ var BABYLON;
                     target = target[effectiveTarget[i]];
                 }
                 // Return appropriate value with its type
-                if (target instanceof Boolean)
+                if (typeof (target) === "boolean")
                     return values[0] === "true";
-                if (target instanceof String)
+                if (typeof (target) === "string")
                     return values[0];
                 // Parameters with multiple values such as Vector3 etc.
                 var split = new Array();
@@ -20401,8 +20413,12 @@ var BABYLON;
                     for (var i = 0; i < parsedAction.properties.length; i++) {
                         var value = parsedAction.properties[i].value;
                         var name = parsedAction.properties[i].name;
+                        var targetType = parsedAction.properties[i].targetType;
                         if (name === "target")
-                            value = target = scene.getNodeByName(value);
+                            if (targetType != null && targetType === "SceneProperties")
+                                value = target = scene;
+                            else
+                                value = target = scene.getNodeByName(value);
                         else if (name === "parent")
                             value = scene.getNodeByName(value);
                         else if (name === "sound")
@@ -20419,7 +20435,12 @@ var BABYLON;
                         parameters.push(value);
                     }
                 }
-                parameters.push(condition);
+                if (combineArray === null) {
+                    parameters.push(condition);
+                }
+                else {
+                    parameters.push(null);
+                }
                 // If interpolate value action
                 if (parsedAction.name === "InterpolateValueAction") {
                     var param = parameters[parameters.length - 2];
@@ -20452,7 +20473,7 @@ var BABYLON;
                 var trigger = parsedActions.children[i];
                 if (trigger.properties.length > 0) {
                     var param = trigger.properties[0].value;
-                    var value = trigger.properties[0].targetType == null ? param : scene.getMeshByName(param);
+                    var value = trigger.properties[0].targetType === null ? param : scene.getMeshByName(param);
                     triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: value };
                 }
                 else

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 17 - 15
babylon.2.1-alpha.js