@pixi/3d
    Preparing search index...

    Class Frustum

    A volume bounded by six planes that face inward, most often the volume a camera sees

    Each Camera3D has one as Camera3D#frustum. Test against it to skip work for things the camera can't see, or build your own from a matrix or from planes to cull against another volume.

    const onScreen = enemies.filter((enemy: Mesh3D) =>
    camera.frustum.intersectsSphere(enemy.boundingSphere),
    );
    Index
    • Creates a new Frustum

      A plane left out defaults to new Plane(): normal (1, 0, 0), constant 0.

      Parameters

      • Optionalp0: Plane

        The first plane

      • Optionalp1: Plane

        The second plane

      • Optionalp2: Plane

        The third plane

      • Optionalp3: Plane

        The fourth plane

      • Optionalp4: Plane

        The fifth plane

      • Optionalp5: Plane

        The sixth plane

      Returns Frustum

    • get planesData(): Float32Array
      Advanced

      The six planes as 24 floats, [nx, ny, nz, c] per plane in Frustum#getPlane order

      This is the frustum's own storage, not a copy: writing to it changes the frustum. Pass it to your own shader to cull on the GPU.

      Returns Float32Array

      device.queue.writeBuffer(frustumBuffer, 0, camera.frustum.planesData);
      
    • Creates a new Frustum with the same planes

      Returns Frustum

      The new frustum

      camera.cullFrustum = camera.frustum.clone();
      
    • Returns true when point lies inside this frustum (boundary is inclusive)

      Parameters

      Returns boolean

      Whether the point is inside this frustum

      marker.visible = !camera.frustum.containsPoint(objective.position);
      
    • Copies frustum into this frustum

      Parameters

      • frustum: Frustum

        The frustum to copy from

      Returns this

      This frustum for chaining

      frozenFrustum.copyFrom(camera.frustum);
      camera.cullFrustum = frozenFrustum;
    • Copies this frustum into target and returns it

      Type Parameters

      Parameters

      • target: T

        The frustum to copy into

      Returns T

      The given target

      camera.frustum.copyTo(debugFrustum);
      
    • Returns true when all six planes match frustum exactly, with no tolerance

      Parameters

      • frustum: Frustum

        The frustum to compare with

      Returns boolean

      Whether all six planes match

      if (!camera.frustum.equals(lastFrustum)) {
      lastFrustum.copyFrom(camera.frustum);
      refreshVisibleList();
      }
    • Writes plane index into out and returns it

      After Frustum#setFromProjectionMatrix the planes are ordered right, left, bottom, top, far, near.

      Parameters

      • index: number

        The plane index, 0 to 5

      • Optionalout: Plane

        Optional plane to write into; a new Plane when omitted

      Returns Plane

      The written plane

      const near = camera.frustum.getPlane(5, new Plane());
      const distanceInFront = near.distanceToPoint(pickup.position);
    • Returns true when box and this frustum overlap

      Like most culling tests it errs towards true: a box just outside a corner of the frustum can pass, but a box that overlaps it never fails.

      Parameters

      • box: Box

        The box to test

      Returns boolean

      Whether the box and this frustum overlap

      building.getLocalBounds(bounds).applyMatrix4(building.worldTransform);
      if (camera.frustum.intersectsBox(bounds)) updateWindowLights(building);
    • Returns true when sphere and this frustum overlap

      Like Frustum#intersectsBox it errs towards true near the frustum's corners. Empty spheres (radius < 0) never intersect.

      Parameters

      • sphere: Sphere

        The sphere to test

      Returns boolean

      Whether the sphere and this frustum overlap

      if (camera.frustum.intersectsSphere(enemy.boundingSphere)) enemy.updateAnimation(dt);
      
    • Sets the six planes of this frustum

      Each plane's normal must be unit length and point into the volume.

      Parameters

      • p0: Plane

        The first plane

      • p1: Plane

        The second plane

      • p2: Plane

        The third plane

      • p3: Plane

        The fourth plane

      • p4: Plane

        The fifth plane

      • p5: Plane

        The sixth plane

      Returns this

      This frustum for chaining

      camera.cullFrustum = new Frustum().set(
      new Plane(new Vector3(1, 0, 0), 20),
      new Plane(new Vector3(-1, 0, 0), 20),
      new Plane(new Vector3(0, 1, 0), 0),
      new Plane(new Vector3(0, -1, 0), 10),
      new Plane(new Vector3(0, 0, 1), 20),
      new Plane(new Vector3(0, 0, -1), 20),
      );
    • Sets the six planes to the volume that matrix maps onto the screen

      The planes come out in the space the matrix maps from: world space for a view-projection matrix, view space for a projection matrix alone. They are normalized, so distances to them are in that space's units. The matrix must map depth to [-1, 1], as Matrix4#makePerspective and Matrix4#makeOrthographic do.

      Parameters

      • matrix: Matrix4

        The matrix to extract clipping planes from

      Returns this

      This frustum for chaining

      const spotlightView = new Frustum().setFromProjectionMatrix(securityCamera.viewProjection);
      const spotted = spotlightView.containsPoint(player.position);
    • Returns a string representation of this frustum

      Returns string

      The string [@pixi/3d/math:Frustum]

      console.log(`${camera.frustum}`);