SolidParticle.intersectsMesh() or Scene.pickWithRay() or Ray.intersectsMesh()

Hi all!

I have to do some hit-analysis of a gun in a flightsim. The gunfire is done using the SolidParticleSystem. Currently I do the hit analysis using SolidParticle.intersectsMesh() as proposed by the SolidParticleSystem documentation. Works ok, but is quite inaccurate bc. of AABB intersection testing. Therefor I already refine by GroundMesh.getHeightAtCoordinates() for terrain hits.
It springs to mind using the ray-casting for more accurate intersection testing.

My question is: What is the best strategy?

  • Is it feasible to use SolidParticle.intersectsMesh() first and in case of a hit refine that with a Ray.intersectsMesh()?
  • Don’t do SolidParticle.intersectsMesh() upfront and use Ray.intersectsMesh() with any potential target directly?
  • Use Scene.pickWithRay() directly (making sure that the scene is properly configured concerning isPickable)?
  • For terrain, use raycasting or try to find intersection point with GroundMesh.getHeightAtCoordinates()?

Thank you for any opinion,

. J

If you know your projected way and the items you are colliding with are not dynamic, you could cast a ray in this direction and know when and what it will hit (you know the velocity, you know the direction, kaboom).

If they are dynamic, you will need to calculated the trajectory much more often, but ray intersections will be the most accurate way to get collisions. You could use intersectsMesh to a general idea of whether or not the object is colliding against the bounding box. This will make the calculations a bit more efficient…

Hi @RaananW!

Thank you for the quick response! Yes, I actually already do the dynamic case you describe.
But to me it seem that doing intersectsMesh() upfront is a waste of time, bc. raycasting does it internally anyway?

From abstractMesh.ts:

public intersects(ray: Ray, fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate, onlyBoundingInfo = false): PickingInfo {
    var pickingInfo = new PickingInfo();
    const intersectionThreshold = this.getClassName() === "InstancedLinesMesh" || this.getClassName() === "LinesMesh" ? (this as any).intersectionThreshold : 0;
    const boundingInfo = this._boundingInfo;
    if (!this.subMeshes || !boundingInfo || !ray.intersectsSphere(boundingInfo.boundingSphere, intersectionThreshold) || !ray.intersectsBox(boundingInfo.boundingBox, intersectionThreshold)) {
        return pickingInfo;

Well, when you are right, you are right! :slight_smile:

Unneeded. Ray tracing is the right way…

1 Like