@pixi/3d
    Preparing search index...

    Class Box

    An axis-aligned bounding box (AABB), spanning from its min corner to its max corner

    Use one to bound a mesh or a group and to run cheap overlap, culling and picking tests before precise ones. Container3D#getLocalBounds measures one for a subtree.

    const squadBounds = new Box();

    for (const soldier of squad) squadBounds.expandByPoint(soldier.position);

    const rallyPoint = squadBounds.getCenter(new Vector3());

    Ray#intersectBox For the point where a ray hits the box

    Index
    • Creates a new Box

      Left out, the box starts empty, so the first Box#expandByPoint gives a tight fit. Vectors passed in become the box's corners; they are not copied.

      Parameters

      • Optionalmin: Vector3

        The minimum corner of the box

      • Optionalmax: Vector3

        The maximum corner of the box

      Returns Box

    max: Vector3

    The corner with the largest x, y and z; -Infinity on every axis in a new, empty box

    const roofHeight = levelBounds.max.y;
    
    min: Vector3

    The corner with the smallest x, y and z; +Infinity on every axis in a new, empty box

    const floorHeight = levelBounds.min.y;
    
    type: SHAPE_PRIMITIVE_3D = 'box'

    Names the shape without an instanceof check, like the type on pixi's 2D shapes

    'box'
    
    • get depth(): number

      The depth (Z extent) of this box; -Infinity for a new, empty box

      Returns number

      const footprint = bounds.width * bounds.depth;
      
    • get height(): number

      The height (Y extent) of this box; -Infinity for a new, empty box

      Returns number

      nameTag.position.y = bounds.max.y + 0.1 * bounds.height;
      
    • get width(): number

      The width (X extent) of this box; -Infinity for a new, empty box, where Box#getSize gives 0

      Returns number

      const footprint = bounds.width * bounds.depth;
      
    • Transforms this box by an affine matrix, then fits a new axis-aligned box around the result

      The new box holds all eight transformed corners, so rotating a box can grow it. An empty box stays empty.

      matrix must be affine (bottom row [0, 0, 0, 1]), as a Container3D#worldTransform always is and a projection matrix isn't.

      Parameters

      • matrix: Matrix4

        The affine matrix to transform by

      • out: Box = ...

        Target to write the result into instead of mutating this box

      Returns this

      The result box for chaining

      const worldBounds = new Box();

      mesh.geometry.bounds3D.applyMatrix4(mesh.worldTransform, worldBounds);
    • Writes the closest point on this box to point into out (or a new Vector3)

      A point inside the box comes back unchanged.

      Parameters

      • point: PointData3D

        The point to clamp

      • Optionalout: Vector3

        Optional vector to write into; a new Vector3 when omitted

      Returns Vector3

      The closest point on this box

      const kept = new Vector3();

      app.ticker.add(() => {
      arena.clampPoint(player.position, kept);
      player.position.copyFrom(kept);
      });
    • Creates a new Box with the same corners

      Returns Box

      The new box

      const padded = bounds.clone().expandByPoint(spawnPoint);
      
    • Returns true when box is fully inside this box (boundary is inclusive)

      A new, empty box counts as inside any box.

      Parameters

      • box: Box

        The box to test

      Returns boolean

      Whether the box is fully inside this box

      const fitsOnShelf = shelfBounds.containsBox(itemBounds);
      
    • Returns true when point is inside this box (boundary is inclusive)

      Parameters

      Returns boolean

      Whether the point is inside this box

      if (pickupZone.containsPoint(player.position)) collect(pickup);
      
    • Copies box into this box

      Parameters

      • box: Box

        The box to copy from

      Returns this

      This box for chaining

      const bounds = new Box().copyFrom(geometry.bounds3D);
      
    • Copies this box into target and returns it

      Type Parameters

      Parameters

      • target: T

        The box to copy into

      Returns T

      The given target

      geometry.bounds3D.copyTo(cachedBounds);
      
    • Returns the Euclidean distance from point to the closest point on this box (0 if inside)

      Parameters

      Returns number

      The distance to the closest point on this box

      const inReach = doorBounds.distanceToPoint(player.position) < 1.5;
      
    • Returns true when both corners match box exactly (no epsilon tolerance)

      Parameters

      • box: Box

        The box to compare with

      Returns boolean

      Whether both corners match

      if (!bounds.equals(lastBounds)) rebuildNavGrid(bounds);
      
    • Grows this box to enclose point

      Parameters

      • point: PointData3D

        The point to enclose

      • out: Box = ...

        Target to write the result into instead of mutating this box

      Returns this

      The result box for chaining

      const routeBounds = new Box();

      for (const waypoint of route) routeBounds.expandByPoint(waypoint);
    • Copies this box into out (or a new Box), so a box answers getBounds like a Sphere

      Parameters

      • Optionalout: Box

        Optional box to write into; a new Box when omitted

      Returns Box

      The bounds of this box

      const bounds = volume.getBounds(scratchBox);
      
    • Writes the center of this box into out (or a new Vector3)

      Empty boxes return (0, 0, 0).

      Parameters

      • Optionalout: Vector3

        Optional vector to write into; a new Vector3 when omitted

      Returns Vector3

      The center of this box

      const center = new Vector3();

      camera.lookAt(model.getLocalBounds().getCenter(center));
    • Writes the size (max - min) of this box into out (or a new Vector3)

      Empty boxes return (0, 0, 0).

      Parameters

      • Optionalout: Vector3

        Optional vector to write into; a new Vector3 when omitted

      Returns Vector3

      The size of this box

      const size = model.getLocalBounds().getSize(new Vector3());

      model.scale.set(2 / Math.max(size.x, size.y, size.z));
    • Returns true when this box and box overlap; boxes that only touch count

      Parameters

      • box: Box

        The box to test

      Returns boolean

      Whether the boxes overlap

      if (playerBounds.intersectsBox(doorBounds)) openDoor();
      
    • Returns true when plane passes through this box or touches it

      Parameters

      • plane: Plane

        The plane to test

      Returns boolean

      Whether the plane passes through or touches the box

      const wading = playerBounds.intersectsPlane(waterSurface);
      
    • Returns true when ray hits this box; same as Ray#intersectsBox

      Parameters

      • ray: Ray

        The ray to test

      Returns boolean

      Whether the ray hits this box

      view3d.on('pointermove', (e) => {
      hovered = buttonBounds.intersectsRay(view3d.screenToRay(e.global, pointerRay));
      });
    • Returns true when this box and sphere overlap; an empty sphere never does

      Parameters

      • sphere: Sphere

        The sphere to test

      Returns boolean

      Whether the box and sphere overlap

      for (const crate of crates) {
      if (crate.bounds.intersectsSphere(blastRadius)) crate.shatter();
      }
    • Returns true when max is below min on any axis, as in a new box

      A flat box, with min equal to max on an axis, is not empty: it holds the points on it.

      Returns boolean

      Whether this box is empty

      if (!selectionBounds.isEmpty()) camera.lookAt(selectionBounds.getCenter());
      
    • Resets this box to empty (min at +Infinity, max at -Infinity), ready to grow again

      Returns this

      This box for chaining

      trailBounds.makeEmpty();
      for (const point of trail) trailBounds.expandByPoint(point);
    • Sets the corners of this box to min and max, copying their values

      Parameters

      Returns this

      This box for chaining

      triggerZone.set({ x: -2, y: 0, z: -2 }, { x: 2, y: 3, z: 2 });
      
    • Advanced

      Returns a string representation of this box

      Returns string

      A string in the form [@pixi/3d/math:Box min=(0, 0, 0) max=(1, 1, 1)]

    • Grows this box to enclose box

      Parameters

      • box: Box

        The box to enclose

      • out: Box = ...

        Target to write the result into instead of mutating this box

      Returns this

      The result box for chaining

      const levelBounds = new Box();

      for (const room of rooms) levelBounds.union(room.bounds);
    • Creates a box centred at center with the given full size

      A number makes a cube; a point sets the size of each axis.

      Parameters

      • center: PointData3D

        The center of the box

      • size: number | PointData3D

        The full size of the box, uniform or per-axis

      Returns Box

      The new box

      const crate = Box.fromCenterSize({ x: 0, y: 0.5, z: 0 }, 1);
      const pickupZone = Box.fromCenterSize(player.position, { x: 4, y: 2, z: 4 });