Browse Source

Bounding info circular dependencies

sebavan 6 years ago
parent
commit
5df8a21851

+ 2 - 11
Tools/Config/tempCircularValidation/core.json

@@ -8,12 +8,8 @@
     "../../src/Culling/Octrees/octreeBlock.ts": [
         "../../src/Culling/Octrees/octree.ts"
     ],
-    "../../src/Culling/boundingInfo.ts": [
-        "../../src/Meshes/abstractMesh.ts"
-    ],
     "../../src/Engines/engine.ts": [
-        "../../src/Materials/Textures/internalTexture.ts",
-        "../../src/Materials/material.ts"
+        "../../src/Materials/Textures/internalTexture.ts"
     ],
     "../../src/Gizmos/boundingBoxGizmo.ts": [
         "../../src/Behaviors/Meshes/pointerDragBehavior.ts"
@@ -52,10 +48,6 @@
         "../../src/Materials/materialHelper.ts",
         "../../src/scene.ts"
     ],
-    "../../src/Meshes/abstractMesh.ts": [
-        "../../src/Culling/boundingInfo.ts",
-        "../../src/Engines/engine.ts"
-    ],
     "../../src/Meshes/geometry.ts": [
         "../../src/Meshes/mesh.ts"
     ],
@@ -63,7 +55,6 @@
         "../../src/Meshes/geometry.ts"
     ],
     "../../src/Meshes/subMesh.ts": [
-        "../../src/Culling/boundingInfo.ts",
         "../../src/Materials/material.ts"
     ],
     "../../src/Misc/filesInput.ts": [
@@ -102,5 +93,5 @@
     "../../src/scene.ts": [
         "../../src/Materials/standardMaterial.ts"
     ],
-    "errorCount": 37
+    "errorCount": 32
 }

+ 4 - 4
src/Culling/boundingInfo.ts

@@ -1,7 +1,7 @@
 import { DeepImmutable } from "../types";
 import { ArrayTools } from "../Misc/arrayTools";
 import { Matrix, Vector3, Plane } from "../Maths/math";
-import { AbstractMesh } from "../Meshes/abstractMesh";
+import { Constants } from "../Engines/constants";
 import { Collider } from "../Collisions/collider";
 
 import { BoundingBox } from "./boundingBox";
@@ -159,8 +159,8 @@ import { BoundingSphere } from "./boundingSphere";
          * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)
          * @returns true if the bounding info is in the frustum planes
          */
-        public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>, strategy: number = AbstractMesh.CULLINGSTRATEGY_STANDARD): boolean {
-            let inclusionTest = (strategy === AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION || strategy === AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY);
+        public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>, strategy: number = Constants.MESHES_CULLINGSTRATEGY_STANDARD): boolean {
+            let inclusionTest = (strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY);
             if (inclusionTest) {
                 if (this.boundingSphere.isCenterInFrustum(frustumPlanes)) {
                     return true;
@@ -171,7 +171,7 @@ import { BoundingSphere } from "./boundingSphere";
                 return false;
             }
 
-            let bSphereOnlyTest = (strategy === AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY || strategy === AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY);
+            let bSphereOnlyTest = (strategy === Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY);
             if (bSphereOnlyTest) {
                 return true;
             }

+ 35 - 0
src/Engines/constants.ts

@@ -344,4 +344,39 @@ export class Constants {
      * Special billboard mode where the particle will be biilboard to the camera but rotated to align with direction
      */
     public static readonly PARTICLES_BILLBOARDMODE_STRETCHED = 8;
+
+    /** Default culling strategy : this is an exclusion test and it's the more accurate.
+     *  Test order :
+     *  Is the bounding sphere outside the frustum ?
+     *  If not, are the bounding box vertices outside the frustum ?
+     *  It not, then the cullable object is in the frustum.
+     */
+    public static readonly MESHES_CULLINGSTRATEGY_STANDARD = 0;
+    /** Culling strategy : Bounding Sphere Only.
+     *  This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.
+     *  It's also less accurate than the standard because some not visible objects can still be selected.
+     *  Test : is the bounding sphere outside the frustum ?
+     *  If not, then the cullable object is in the frustum.
+     */
+    public static readonly MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = 1;
+    /** Culling strategy : Optimistic Inclusion.
+     *  This in an inclusion test first, then the standard exclusion test.
+     *  This can be faster when a cullable object is expected to be almost always in the camera frustum.
+     *  This could also be a little slower than the standard test when the tested object center is not the frustum but one of its bounding box vertex is still inside.
+     *  Anyway, it's as accurate as the standard strategy.
+     *  Test :
+     *  Is the cullable object bounding sphere center in the frustum ?
+     *  If not, apply the default culling strategy.
+     */
+    public static readonly MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = 2;
+    /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.
+     *  This in an inclusion test first, then the bounding sphere only exclusion test.
+     *  This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.
+     *  This could also be a little slower than the BoundingSphereOnly strategy when the tested object center is not in the frustum but its bounding sphere still intersects it.
+     *  It's less accurate than the standard strategy and as accurate as the BoundingSphereOnly strategy.
+     *  Test :
+     *  Is the cullable object bounding sphere center in the frustum ?
+     *  If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.
+     */
+    public static readonly MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = 3;
 }

+ 4 - 4
src/Meshes/abstractMesh.ts

@@ -74,14 +74,14 @@ import { Constants } from "../Engines/constants";
          *  If not, are the bounding box vertices outside the frustum ?
          *  It not, then the cullable object is in the frustum.
          */
-        public static readonly CULLINGSTRATEGY_STANDARD = 0;
+        public static readonly CULLINGSTRATEGY_STANDARD = Constants.MESHES_CULLINGSTRATEGY_STANDARD;
         /** Culling strategy : Bounding Sphere Only.
          *  This is an exclusion test. It's faster than the standard strategy because the bounding box is not tested.
          *  It's also less accurate than the standard because some not visible objects can still be selected.
          *  Test : is the bounding sphere outside the frustum ?
          *  If not, then the cullable object is in the frustum.
          */
-        public static readonly CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = 1;
+        public static readonly CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY = Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY;
         /** Culling strategy : Optimistic Inclusion.
          *  This in an inclusion test first, then the standard exclusion test.
          *  This can be faster when a cullable object is expected to be almost always in the camera frustum.
@@ -91,7 +91,7 @@ import { Constants } from "../Engines/constants";
          *  Is the cullable object bounding sphere center in the frustum ?
          *  If not, apply the default culling strategy.
          */
-        public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = 2;
+        public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION = Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION;
         /** Culling strategy : Optimistic Inclusion then Bounding Sphere Only.
          *  This in an inclusion test first, then the bounding sphere only exclusion test.
          *  This can be the fastest test when a cullable object is expected to be almost always in the camera frustum.
@@ -101,7 +101,7 @@ import { Constants } from "../Engines/constants";
          *  Is the cullable object bounding sphere center in the frustum ?
          *  If not, apply the Bounding Sphere Only strategy. No Bounding Box is tested here.
          */
-        public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = 3;
+        public static readonly CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY = Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;
 
         /**
          * No billboard