Преглед изворни кода

mesh.freezeWorldMatrix() / mesh.unfreezeWorldMatrix()
mesh.alwaysSelectAsActiveMesh

David Catuhe пре 10 година
родитељ
комит
e2df662d61

+ 13 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -41,6 +41,7 @@ var BABYLON;
             this.useOctreeForPicking = true;
             this.useOctreeForCollisions = true;
             this.layerMask = 0x0FFFFFFF;
+            this.alwaysSelectAsActiveMesh = false;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
             // Collisions
@@ -69,6 +70,7 @@ var BABYLON;
             this._renderId = 0;
             this._intersectionsInProgress = new Array();
             this._onAfterWorldMatrixUpdate = new Array();
+            this._isWorldMatrixFrozen = false;
             scene.addMesh(this);
         }
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_NONE", {
@@ -173,6 +175,14 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        AbstractMesh.prototype.freezeWorldMatrix = function () {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = true;
+        };
+        AbstractMesh.prototype.unfreezeWorldMatrix = function () {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = false;
+        };
         AbstractMesh.prototype.rotate = function (axis, amount, space) {
             if (!this.rotationQuaternion) {
                 this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
@@ -352,6 +362,9 @@ var BABYLON;
             }
         };
         AbstractMesh.prototype.computeWorldMatrix = function (force) {
+            if (this._isWorldMatrixFrozen) {
+                return this._worldMatrix;
+            }
             if (!force && (this._currentRenderId === this.getScene().getRenderId() || this.isSynchronized(true))) {
                 return this._worldMatrix;
             }

+ 18 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -65,6 +65,8 @@
 
         public layerMask: number = 0x0FFFFFFF;
 
+        public alwaysSelectAsActiveMesh = false;
+
         // Physics
         public _physicImpostor = PhysicsEngine.NoImpostor;
         public _physicsMass: number;
@@ -107,6 +109,8 @@
 
         private _onAfterWorldMatrixUpdate = new Array<(mesh: AbstractMesh) => void>();
 
+        private _isWorldMatrixFrozen = false;
+
         // Loading properties
         public _waitingActions: any;
 
@@ -182,6 +186,16 @@
             return this._absolutePosition;
         }
 
+        public freezeWorldMatrix() {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = true;
+        }
+
+        public unfreezeWorldMatrix() {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = false;
+        }
+
         public rotate(axis: Vector3, amount: number, space: Space): void {
             if (!this.rotationQuaternion) {
                 this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
@@ -393,6 +407,10 @@
         }
 
         public computeWorldMatrix(force?: boolean): Matrix {
+            if (this._isWorldMatrixFrozen) {
+                return this._worldMatrix;
+            }
+
             if (!force && (this._currentRenderId === this.getScene().getRenderId() || this.isSynchronized(true))) {
                 return this._worldMatrix;
             }

+ 4 - 0
Babylon/Rendering/babylon.depthRenderer.js

@@ -17,6 +17,10 @@ var BABYLON;
             this._depthMap.refreshRate = 1;
             this._depthMap.renderParticles = false;
             this._depthMap.renderList = null;
+            // set default depth value to 1.0 (far away)
+            this._depthMap.onClear = function (engine) {
+                engine.clear(new BABYLON.Color4(1.0, 1.0, 1.0, 1.0), true, true);
+            };
             // Custom render function
             var renderSubMesh = function (subMesh) {
                 var mesh = subMesh.getRenderingMesh();

+ 6 - 1
Babylon/Rendering/babylon.depthRenderer.ts

@@ -16,12 +16,17 @@
             var engine = scene.getEngine();
 
             // Render target
-            this._depthMap = new RenderTargetTexture("depthMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight()}, this._scene, false, true, type);
+            this._depthMap = new RenderTargetTexture("depthMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this._scene, false, true, type);
             this._depthMap.wrapU = Texture.CLAMP_ADDRESSMODE;
             this._depthMap.wrapV = Texture.CLAMP_ADDRESSMODE;
             this._depthMap.refreshRate = 1;
             this._depthMap.renderParticles = false;
             this._depthMap.renderList = null;
+            
+            // set default depth value to 1.0 (far away)
+            this._depthMap.onClear = (engine: Engine) => {
+                engine.clear(new Color4(1.0, 1.0, 1.0, 1.0), true, true);
+            }
 
             // Custom render function
             var renderSubMesh = (subMesh: SubMesh): void => {

+ 3 - 3
Babylon/babylon.scene.js

@@ -911,7 +911,7 @@ var BABYLON;
             return (this._activeMeshes.indexOf(mesh) !== -1);
         };
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
-            if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
+            if (mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
                 var material = subMesh.getMaterial();
                 if (mesh.showSubMeshesBoundingBox) {
                     this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
@@ -962,7 +962,7 @@ var BABYLON;
                     continue;
                 }
                 this._totalVertices += mesh.getTotalVertices();
-                if (!mesh.isReady()) {
+                if (!mesh.isReady() || !mesh.isEnabled()) {
                     continue;
                 }
                 mesh.computeWorldMatrix();
@@ -976,7 +976,7 @@ var BABYLON;
                     continue;
                 }
                 mesh._preActivate();
-                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
+                if (mesh.alwaysSelectAsActiveMesh || mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
                     this._activeMeshes.push(mesh);
                     this.activeCamera._activeMeshes.push(mesh);
                     mesh._activate(this._renderId);

+ 3 - 3
Babylon/babylon.scene.ts

@@ -1175,7 +1175,7 @@
         }
 
         private _evaluateSubMesh(subMesh: SubMesh, mesh: AbstractMesh): void {
-            if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
+            if (mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
                 var material = subMesh.getMaterial();
 
                 if (mesh.showSubMeshesBoundingBox) {
@@ -1236,7 +1236,7 @@
 
                 this._totalVertices += mesh.getTotalVertices();
 
-                if (!mesh.isReady()) {
+                if (!mesh.isReady() || !mesh.isEnabled()) {
                     continue;
                 }
 
@@ -1256,7 +1256,7 @@
 
                 mesh._preActivate();
 
-                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
+                if (mesh.alwaysSelectAsActiveMesh || mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
                     this._activeMeshes.push(mesh);
                     this.activeCamera._activeMeshes.push(mesh);
                     mesh._activate(this._renderId);

+ 20 - 3
babylon.2.1-beta.debug.js

@@ -9111,7 +9111,7 @@ var BABYLON;
             return (this._activeMeshes.indexOf(mesh) !== -1);
         };
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
-            if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
+            if (mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
                 var material = subMesh.getMaterial();
                 if (mesh.showSubMeshesBoundingBox) {
                     this._boundingBoxRenderer.renderList.push(subMesh.getBoundingInfo().boundingBox);
@@ -9162,7 +9162,7 @@ var BABYLON;
                     continue;
                 }
                 this._totalVertices += mesh.getTotalVertices();
-                if (!mesh.isReady()) {
+                if (!mesh.isReady() || !mesh.isEnabled()) {
                     continue;
                 }
                 mesh.computeWorldMatrix();
@@ -9176,7 +9176,7 @@ var BABYLON;
                     continue;
                 }
                 mesh._preActivate();
-                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
+                if (mesh.alwaysSelectAsActiveMesh || mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
                     this._activeMeshes.push(mesh);
                     this.activeCamera._activeMeshes.push(mesh);
                     mesh._activate(this._renderId);
@@ -10142,6 +10142,7 @@ var BABYLON;
             this.useOctreeForPicking = true;
             this.useOctreeForCollisions = true;
             this.layerMask = 0x0FFFFFFF;
+            this.alwaysSelectAsActiveMesh = false;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
             // Collisions
@@ -10170,6 +10171,7 @@ var BABYLON;
             this._renderId = 0;
             this._intersectionsInProgress = new Array();
             this._onAfterWorldMatrixUpdate = new Array();
+            this._isWorldMatrixFrozen = false;
             scene.addMesh(this);
         }
         Object.defineProperty(AbstractMesh, "BILLBOARDMODE_NONE", {
@@ -10274,6 +10276,14 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        AbstractMesh.prototype.freezeWorldMatrix = function () {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = true;
+        };
+        AbstractMesh.prototype.unfreezeWorldMatrix = function () {
+            this.computeWorldMatrix(true);
+            this._isWorldMatrixFrozen = false;
+        };
         AbstractMesh.prototype.rotate = function (axis, amount, space) {
             if (!this.rotationQuaternion) {
                 this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
@@ -10453,6 +10463,9 @@ var BABYLON;
             }
         };
         AbstractMesh.prototype.computeWorldMatrix = function (force) {
+            if (this._isWorldMatrixFrozen) {
+                return this._worldMatrix;
+            }
             if (!force && (this._currentRenderId === this.getScene().getRenderId() || this.isSynchronized(true))) {
                 return this._worldMatrix;
             }
@@ -29585,6 +29598,10 @@ var BABYLON;
             this._depthMap.refreshRate = 1;
             this._depthMap.renderParticles = false;
             this._depthMap.renderList = null;
+            // set default depth value to 1.0 (far away)
+            this._depthMap.onClear = function (engine) {
+                engine.clear(new BABYLON.Color4(1.0, 1.0, 1.0, 1.0), true, true);
+            };
             // Custom render function
             var renderSubMesh = function (subMesh) {
                 var mesh = subMesh.getRenderingMesh();

Разлика између датотеке није приказан због своје велике величине
+ 9 - 9
babylon.2.1-beta.js