Ver código fonte

move bounding info to node

Trevor Baron 6 anos atrás
pai
commit
7a56bce891
3 arquivos alterados com 29 adições e 31 exclusões
  1. 0 20
      src/Meshes/abstractMesh.ts
  2. 29 10
      src/node.ts
  3. 0 1
      tests/validation/config.json

+ 0 - 20
src/Meshes/abstractMesh.ts

@@ -563,8 +563,6 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
     /** @hidden */
     public _masterMesh: Nullable<AbstractMesh>;
     /** @hidden */
-    public _boundingInfo: Nullable<BoundingInfo>;
-    /** @hidden */
     public _renderId = 0;
 
     /**
@@ -1129,24 +1127,6 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         return new Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);
     }
 
-    protected _getBoudingInfoMin() {
-        if (this.subMeshes) {
-            let boundingInfo = this.getBoundingInfo();
-            return boundingInfo.boundingBox.minimumWorld;
-        }else {
-            return new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-        }
-
-    }
-    protected _getBoudingInfoMax() {
-        if (this.subMeshes) {
-            let boundingInfo = this.getBoundingInfo();
-            return boundingInfo.boundingBox.maximumWorld;
-        }else {
-            return new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
-        }
-    }
-
     /**
      * This method recomputes and sets a new BoundingInfo to the mesh unless it is locked.
      * This means the mesh underlying bounding box and sphere are recomputed.

+ 29 - 10
src/node.ts

@@ -10,6 +10,7 @@ import { _DevTools } from './Misc/devTools';
 import { AbstractActionManager } from './Actions/abstractActionManager';
 import { IInspectable } from './Misc/iInspectable';
 import { Tools } from './Misc/tools';
+import { BoundingInfo } from './Culling/boundingInfo';
 
 declare type Animatable = import("./Animations/animatable").Animatable;
 declare type AnimationPropertiesOverride = import("./Animations/animationPropertiesOverride").AnimationPropertiesOverride;
@@ -766,13 +767,6 @@ export class Node implements IBehaviorAware<Node> {
         this._behaviors = [];
     }
 
-    protected _getBoudingInfoMin() {
-        return new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-    }
-    protected _getBoudingInfoMax() {
-        return new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
-    }
-
     /**
      * Parse animation range data from a serialization object and store them into a given node
      * @param node defines where to store the animation ranges
@@ -788,6 +782,22 @@ export class Node implements IBehaviorAware<Node> {
         }
     }
 
+    /** @hidden */
+    public _boundingInfo: Nullable<BoundingInfo>;
+
+    /**
+     * Returns the mesh BoundingInfo object or creates a new one and returns if it was undefined
+     * @returns a BoundingInfo
+     */
+    public getBoundingInfo(): BoundingInfo {
+
+        if (!this._boundingInfo) {
+            this._boundingInfo = new BoundingInfo(new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE), new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE), this._worldMatrix);
+        }
+
+        return this._boundingInfo!;
+    }
+
     /**
      * Return the minimum and maximum world vectors of the entire hierarchy under current mesh
      * @param includeDescendants Include bounding info from descendants as well (true by default)
@@ -800,8 +810,17 @@ export class Node implements IBehaviorAware<Node> {
 
         this.computeWorldMatrix(true);
 
-        let min = this._getBoudingInfoMin();
-        let max = this._getBoudingInfoMax();
+        let min: Vector3;
+        let max: Vector3;
+        let boundingInfo = this.getBoundingInfo();
+
+        if (!(this as any).subMeshes) {
+            min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
+        } else {
+            min = boundingInfo.boundingBox.minimumWorld;
+            max = boundingInfo.boundingBox.maximumWorld;
+        }
 
         if (includeDescendants) {
             let descendants = this.getDescendants(false);
@@ -816,7 +835,7 @@ export class Node implements IBehaviorAware<Node> {
                 }
 
                 //make sure we have the needed params to get mix and max
-                if (!childMesh.getBoundingInfo || childMesh.getTotalVertices() === 0) {
+                if (!childMesh.getTotalVertices || childMesh.getTotalVertices() === 0) {
                     continue;
                 }
 

+ 0 - 1
tests/validation/config.json

@@ -4,7 +4,6 @@
     {
       "title": "Nested BBG",
       "playgroundId": "#ZG0C8B#0",
-      "renderCount": 50,
       "referenceImage": "nested_BBG.png"
     },
     {