BabylonJS/Babylon.js · error

Point Cloud System doesnt contain the Mesh

Error message

Point Cloud System doesnt contain the Mesh

What it means

CloudPoint.intersectsMesh tests whether the point intersects a target mesh. The intersection math positions the point in world space using the owning PointCloudSystem's mesh, so the PCS must have a mesh assigned. If this._pcs.mesh is null (the PCS was created without ever setting/finalizing its mesh), the point cannot be transformed and the method throws.

Source

Thrown at packages/dev/core/src/Particles/cloudPoint.ts:153

     */
    public set quaternion(q: Nullable<Quaternion>) {
        this.rotationQuaternion = q;
    }

    /**
     * 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 bounding sphere is used
     * @returns true if it intersects
     */
    public intersectsMesh(target: Mesh, isSphere: boolean): boolean {
        if (!target.hasBoundingInfo) {
            return false;
        }

        if (!this._pcs.mesh) {
            throw new Error("Point Cloud System doesnt contain the Mesh");
        }

        if (isSphere) {
            return target.getBoundingInfo().boundingSphere.intersectsPoint(this.position.add(this._pcs.mesh.position));
        }

        const bbox = target.getBoundingInfo().boundingBox;

        const maxX = bbox.maximumWorld.x;
        const minX = bbox.minimumWorld.x;
        const maxY = bbox.maximumWorld.y;
        const minY = bbox.minimumWorld.y;
        const maxZ = bbox.maximumWorld.z;
        const minZ = bbox.minimumWorld.z;

        const x = this.position.x + this._pcs.mesh.position.x;
        const y = this.position.y + this._pcs.mesh.position.y;
        const z = this.position.z + this._pcs.mesh.position.z;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Await pcs.buildMeshAsync() before calling intersectsMesh.
  2. Check pcs.mesh for null before intersecting and skip/handle the case.
  3. If the PCS is data-only, convert to a real mesh-based PCS or compute intersection manually from the point position.

Example fix

// before
const hit = point.intersectsMesh(box, false);
// after
await pcs.buildMeshAsync();
const hit = pcs.mesh ? point.intersectsMesh(box, false) : false;
Defensive patterns

Strategy: validation

Validate before calling

if (!pcs.mesh) throw new Error("Call await pcs.buildMeshAsync() before intersect tests");

Type guard

function pcsHasMesh(pcs: PointCloudSystem): boolean {
  return pcs.mesh !== null;
}

Try / catch

try {
  const hit = point.intersectsMesh(target, false);
} catch (e) {
  if (e.message.includes("doesnt contain the Mesh")) {
    await pcs.buildMeshAsync(); // then retry or skip
  } else throw e;
}

Prevention

When it happens

Trigger: Calling cloudPoint.intersectsMesh(target, isSphere) on a point from a PointCloudSystem whose `mesh` property is null — e.g. before buildMeshAsync() completes or on a PCS used purely as a data container.

Common situations: Querying intersections immediately after creating a PointCloudSystem but before awaiting buildMeshAsync(); or after explicitly clearing/disposing the mesh; or on PCS instances used only for point storage.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/698cc0ca445c11ce. Report an issue: GitHub.