소스 검색

Better light WM management

David Catuhe 7 년 전
부모
커밋
2da5a9f101
5개의 변경된 파일38개의 추가작업 그리고 69개의 파일을 삭제
  1. 1 3
      src/Lights/babylon.hemisphericLight.ts
  2. 0 27
      src/Lights/babylon.light.ts
  3. 9 1
      src/Lights/babylon.shadowLight.ts
  4. 1 28
      src/Mesh/babylon.transformNode.ts
  5. 27 10
      src/babylon.node.ts

+ 1 - 3
src/Lights/babylon.hemisphericLight.ts

@@ -19,9 +19,7 @@
          * The light reflection direction, not the incoming direction.
          */
         @serializeAsVector3()
-        public direction: Vector3
-
-        private _worldMatrix: Matrix;
+        public direction: Vector3;
 
         /**
          * Creates a HemisphericLight object in the scene according to the passed direction (Vector3).  

+ 0 - 27
src/Lights/babylon.light.ts

@@ -301,8 +301,6 @@ module BABYLON {
             this._markMeshesAsLightDirty();
         }
 
-        private _parentedWorldMatrix: Matrix;
-
         /**
          * Shadow generator associted to the light.
          * @hidden Internal use only.
@@ -433,31 +431,6 @@ module BABYLON {
 
             return true;
         }
- 
-        /**
-         * Computes and returns the light World matrix
-         * @returns the world matrix 
-         */
-        public getWorldMatrix(): Matrix {
-            this._currentRenderId = this.getScene().getRenderId();
-            this._childRenderId = this._currentRenderId;
-
-            var worldMatrix = this.computeWorldMatrix();
-
-            if (this.parent && this.parent.getWorldMatrix) {
-                if (!this._parentedWorldMatrix) {
-                    this._parentedWorldMatrix = Matrix.Identity();
-                }
-
-                worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._parentedWorldMatrix);
-
-                this._markSyncedWithParent();
-
-                return this._parentedWorldMatrix;
-            }
-
-            return worldMatrix;
-        }
 
         /**
 		 * Sort function to order lights for rendering.

+ 9 - 1
src/Lights/babylon.shadowLight.ts

@@ -206,7 +206,6 @@
          */
         public transformedDirection: Vector3;
 
-        private _worldMatrix: Matrix;
         private _needProjectionMatrixCompute: boolean = true;
 
         /**
@@ -338,6 +337,15 @@
 
             Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);
 
+            if (this.parent && this.parent.getWorldMatrix) {
+                this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+
+                this._markSyncedWithParent();
+            }            
+
+            // Cache the determinant
+            this._worldMatrixDeterminant = this._worldMatrix.determinant();
+
             return this._worldMatrix;
         }
 

+ 1 - 28
src/Mesh/babylon.transformNode.ts

@@ -60,10 +60,7 @@ module BABYLON {
         /** @hidden */
         public _poseMatrix: Matrix;
         private _localWorld = Matrix.Zero();
-        /** @hidden */
-        public _worldMatrix = Matrix.Zero();
-        /** @hidden */
-        public _worldMatrixDeterminant = 0;
+
         private _absolutePosition = Vector3.Zero();
         private _pivotMatrix = Matrix.Identity();
         private _pivotMatrixInverse: Matrix;
@@ -176,30 +173,6 @@ module BABYLON {
         }
 
         /**
-         * Returns the latest update of the World matrix
-         * Returns a Matrix.  
-         */
-        public getWorldMatrix(): Matrix {
-            if (this._currentRenderId !== this.getScene().getRenderId()) {
-                this.computeWorldMatrix();
-            }
-            return this._worldMatrix;
-        }
-
-        /** @hidden */
-        public _getWorldMatrixDeterminant(): number {
-            return this._worldMatrixDeterminant;
-        }
-
-        /**
-         * Returns directly the latest state of the mesh World matrix. 
-         * A Matrix is returned.    
-         */
-        public get worldMatrixFromCache(): Matrix {
-            return this._worldMatrix;
-        }
-
-        /**
          * Copies the parameter passed Matrix into the mesh Pose matrix.  
          * Returns the TransformNode.  
          */

+ 27 - 10
src/babylon.node.ts

@@ -106,7 +106,11 @@
 
         /** @hidden */
         public _worldMatrixWasUpdated = false;
-        private _identityMatrix: Matrix;
+
+        /** @hidden */
+        public _worldMatrix = Matrix.Zero();
+        /** @hidden */
+        public _worldMatrixDeterminant = 0;        
 
         /**
          * Gets a boolean indicating if the node has been disposed
@@ -308,19 +312,32 @@
             return null;
         }
 
+
         /**
-         * Returns the world matrix of the node
-         * @returns a matrix containing the node's world matrix
+         * Returns the latest update of the World matrix
+         * Returns a Matrix.  
          */
         public getWorldMatrix(): Matrix {
-            return Matrix.Identity();
+            if (this._currentRenderId !== this.getScene().getRenderId()) {
+                this.computeWorldMatrix();
+            }
+            return this._worldMatrix;
         }
 
+
         /** @hidden */
         public _getWorldMatrixDeterminant(): number {
-            return 1;
+            return this._worldMatrixDeterminant;
         }
 
+        /**
+         * Returns directly the latest state of the mesh World matrix. 
+         * A Matrix is returned.    
+         */
+        public get worldMatrixFromCache(): Matrix {
+            return this._worldMatrix;
+        }        
+
         // override it in derived class if you add new variables to the cache
         // and call the parent class method
         /** @hidden */
@@ -353,8 +370,8 @@
 
         /** @hidden */
         public _markSyncedWithParent() {
-            if (this.parent) {
-                this._parentRenderId = this.parent._childRenderId;
+            if (this._parentNode) {
+                this._parentRenderId = this._parentNode._childRenderId;
             }
         }
 
@@ -646,10 +663,10 @@
          * @returns the world matrix
          */
         public computeWorldMatrix(force?: boolean, useWasUpdatedFlag?: boolean): Matrix {
-            if (!this._identityMatrix) {
-                this._identityMatrix = Matrix.Identity();
+            if (!this._worldMatrix) {
+                this._worldMatrix = Matrix.Identity();
             }
-            return this._identityMatrix;
+            return this._worldMatrix;
         }
 
         /**