Просмотр исходного кода

Merge pull request #6923 from BabylonJSGuide/master

Correction to intersectsMesh
David Catuhe 5 лет назад
Родитель
Сommit
d3df8d8d87
2 измененных файлов с 28 добавлено и 31 удалено
  1. 1 1
      dist/preview release/what's new.md
  2. 27 30
      src/Particles/cloudPoint.ts

+ 1 - 1
dist/preview release/what's new.md

@@ -6,7 +6,7 @@
 - WIP: WebGPU support (NEED DOC OR SAMPLES) ([Sebavan](https://github.com/sebavan/))
 - .basis texture file format support [Doc](https://doc.babylonjs.com/resources/multi-platform_compressed_textures#basis-file-format) ([TrevorDev](https://github.com/TrevorDev))
 - WIP: Recast navigation mesh and crowd of moving agents [Demo](https://www.babylonjs-playground.com/#AJTRIL) ([CedricGuillemet](https://github.com/CedricGuillemet))
-- Added Point Cloud Particle System ([JohnK](https://github.com/BabylonJSGuide/))
+- Added Points Cloud Particle System ([JohnK](https://github.com/BabylonJSGuide/))
 - Classes decoupling ending up with smaller bundle sizes [Blog](https://medium.com/@babylonjs/size-matters-e0e94dad01a7) ([Deltakosh](https://github.com/deltakosh/))
 - Babylon.js controls [Doc](https://doc.babylonjs.com/features/controls) ([Sebavan](https://github.com/sebavan/) / [Deltakosh](https://github.com/deltakosh/))
 - WebXR updates:

+ 27 - 30
src/Particles/cloudPoint.ts

@@ -138,43 +138,40 @@ export class CloudPoint {
     }
 
     /**
-     * Returns a boolean. True if the particle intersects another particle or another mesh, else false.
-     * The intersection is computed on the particle bounding sphere and Axis Aligned Bounding Box (AABB)
-     * @param target is the object (point or mesh) what the intersection is computed against.
+     * Returns a boolean. True if the particle intersects a mesh, else false
+     * The intersection is computed on the particle position and Axis Aligned Bounding Box (AABB) or Sphere
+     * @param target is the object (point or mesh) what the intersection is computed against
+     * @param isSphere is boolean flag when false (default) bounding box of mesh is used, when true the bouding sphere is used
      * @returns true if it intersects
      */
-    public intersectsMesh(target: Mesh | CloudPoint): boolean {
-        if (!(target instanceof CloudPoint) || !target._boundingInfo) {
+    public intersectsMesh(target: Mesh, isSphere: boolean): boolean {
+        if (!target._boundingInfo) {
             return false;
         }
-        const radius = this._pcs._size;
-        let maxX: number = 0;
-        let minX: number = 0;
-        let maxY: number = 0;
-        let minY: number = 0;
-        let maxZ: number = 0;
-        let minZ: number = 0;
-        if (target instanceof CloudPoint) {
-            maxX = target.position.x + radius;
-            minX = target.position.x - radius;
-            maxY = target.position.y + radius;
-            minY = target.position.y - radius;
-            maxZ = target.position.z + radius;
-            minZ = target.position.z - radius;
+        isSphere = isSphere ? isSphere : false;
+
+        if (isSphere) {
+            return target.getBoundingInfo().boundingSphere.intersectsPoint(this.position.add(this._pcs.mesh.position));
         }
+        else {
+            let maxX = 0;
+            let minX = 0;
+            let maxY = 0;
+            let minY = 0;
+            let maxZ = 0;
+            let minZ = 0;
+            maxX = target.getBoundingInfo().boundingBox.maximumWorld.x;
+            minX = target.getBoundingInfo().boundingBox.minimumWorld.x;
+            maxY = target.getBoundingInfo().boundingBox.maximumWorld.y;
+            minY = target.getBoundingInfo().boundingBox.minimumWorld.y;
+            maxZ = target.getBoundingInfo().boundingBox.maximumWorld.z;
+            minZ = target.getBoundingInfo().boundingBox.minimumWorld.z;
 
-        if (target._boundingInfo) {
-            maxX = target._boundingInfo.maximum.x;
-            minX = target._boundingInfo.minimum.x;
-            maxY = target._boundingInfo.maximum.y;
-            minY = target._boundingInfo.minimum.y;
-            maxZ = target._boundingInfo.maximum.z;
-            minZ = target._boundingInfo.minimum.z;
+            let x = this.position.x + this._pcs.mesh.position.x;
+            let y = this.position.y + this._pcs.mesh.position.y;
+            let z = this.position.z + this._pcs.mesh.position.z;
+            return minX <= x  &&  x <= maxX && minY <= y && y <= maxY && minZ <= z && z <= maxZ;
         }
-        const x = this.position.x;
-        const y = this.position.y;
-        const z = this.position.z;
-        return (minX <= x + radius || maxX >= x - radius) && (minY <= y + radius || maxY >= y - radius) && (minZ <= z + radius || maxZ >= z - radius);
     }
 
     /**