melonJS
    Preparing search index...

    Class AABB3d

    A 3D axis-aligned bounding box — the 3D sibling of Bounds.

    Used by Octree as the bounding primitive of every node (root, subnodes, queries). Intentionally minimal: only the operations the Octree hot path needs are implemented, with a small handful of helpers (AABB3d#contains, AABB3d#overlaps, AABB3d#overlapsSphere) for test-driven querySphere / queryAABB callers.

    Coordinate convention matches the rest of melonJS 3D code (see Camera3d): Y-down, +Z forward / away from the camera.

    Lives next to Octree under physics/broadphase/ rather than math/ to mirror Bounds (which lives in physics/, not math/). It originated as a broadphase-internal primitive; it is now also the public 3D-bounds type returned by Mesh#getBounds3d (the 3D analog of Renderable#getBoundsBounds), built from mesh geometry via AABB3d#fromVertices.

    Index

    Constructors

    • Construct an empty AABB (min = +∞, max = −∞). The empty AABB satisfies addPoint(p) => min = max = p for the first point added, and overlaps(b) => false against any other AABB — same convention as Bounds.

      Parameters

      • Optionalmin: XYZPoint

        optional initial minimum corner

      • Optionalmax: XYZPoint

        optional initial maximum corner

      Returns AABB3d

    Properties

    max: XYZPoint
    min: XYZPoint

    Accessors

    Methods

    • Build this AABB from a flat vertex buffer (x,y,z triplets), optionally transformed by a column-major 4×4 matrix — the bridge from raw mesh / glTF geometry (e.g. a Mesh's vertices or a parsed glTF node) to an AABB3d. Replaces the current bounds (seeds empty, then folds in the count vertices); for the point-array form use AABB3d#addPoint.

      The per-vertex math is delegated to transformedBounds (the shared math/vertex.ts helper) rather than duplicated here, so the flat-buffer ↔ AABB conversion stays in one place. Allocation-free.

      Parameters

      • src: Float32Array

        source vertex positions (x,y,z triplets)

      • count: number

        number of vertices to read from src

      • Optionalmatrix: ArrayLike<number>

        optional column-major 4×4 (16 elements); identity if omitted

      Returns AABB3d

      this AABB, for chaining

      // bounds of a glTF node's geometry under its world transform
      const box = new AABB3d().fromVertices(node.vertices, node.vertexCount, node.world);
    • True if every coordinate is a finite number. Used by the Octree to reject inserts whose bounding box is the empty AABB (a sprite with no shape and never updated) — without this guard a ±Infinity corner would silently classify into an arbitrary octant and never come back out via remove.

      Returns boolean

    • True if this AABB overlaps the given AABB on every axis. The intersection includes the boundary (shared face/edge/corner counts as overlap), same convention as Bounds.overlaps so Octree candidate sets don't drop items that sit exactly on an octant boundary.

      Parameters

      • aabb: AABB3d

        the other AABB to test against

      Returns boolean

    • True if this AABB overlaps a sphere. Computes the squared distance from the sphere center to the nearest point on the AABB and compares against — avoids the sqrt on the hot path. Used by Octree.querySphere.

      Parameters

      • cx: number

        sphere center x

      • cy: number

        sphere center y

      • cz: number

        sphere center z

      • r: number

        sphere radius (must be ≥ 0; r=0 becomes a point-in-AABB test)

      Returns boolean

    • Set min and max corners directly. Mirror of Bounds.setMinMax.

      Parameters

      • minX: number

        minimum corner x

      • minY: number

        minimum corner y

      • minZ: number

        minimum corner z

      • maxX: number

        maximum corner x

      • maxY: number

        maximum corner y

      • maxZ: number

        maximum corner z

      Returns void