Engine API Reference - v2.15.3
    Preparing search index...

    Class Frustum

    A frustum is a shape that defines the viewing space of a camera. It can be used to determine visibility of points and bounding spheres. Typically, you would not create a Frustum shape directly, but instead query CameraComponent#frustum.

    Index

    Constructors

    Properties

    planes: Plane[] = []

    The six planes that make up the frustum.

    Methods

    • Expands this frustum to also contain another frustum. For each of the 6 planes, the plane that is further out (larger distance) is kept, creating a combined frustum that encompasses both. This is useful for multi-view rendering such as stereo XR where culling should keep objects visible in any view.

      Note: This method assumes both frustums have similar orientation (parallel views). This is valid for WebXR stereo rendering where eyes use parallel projection with only a horizontal offset, not toe-in convergence.

      Parameters

      • other: Frustum

        The other frustum to add.

      Returns Frustum

      Self for chaining.

    • Returns a clone of the specified frustum.

      Returns Frustum

      A duplicate frustum.

      const frustum = new pc.Frustum();
      const clone = frustum.clone();
    • Tests whether a point is inside the frustum. Note that points lying in a frustum plane are considered to be outside the frustum.

      Parameters

      • point: Vec3

        The point to test.

      Returns boolean

      True if the point is inside the frustum, false otherwise.

    • Tests whether a bounding sphere intersects the frustum. If the sphere is outside the frustum, zero is returned. If the sphere intersects the frustum, 1 is returned. If the sphere is completely inside the frustum, 2 is returned. Note that a sphere touching a frustum plane from the outside is considered to be outside the frustum.

      Parameters

      Returns number

      0 if the bounding sphere is outside the frustum, 1 if it intersects the frustum and 2 if it is contained by the frustum.

    • Copies the contents of a source frustum to a destination frustum.

      Parameters

      • src: Frustum

        A source frustum to copy to the destination frustum.

      Returns Frustum

      Self for chaining.

      const src = entity.camera.frustum;
      const dst = new pc.Frustum();
      dst.copy(src);
    • Updates the frustum shape based on the supplied 4x4 matrix.

      Parameters

      • matrix: Mat4

        The matrix describing the shape of the frustum.

      Returns void

      // Create a perspective projection matrix
      const projection = new pc.Mat4();
      projection.setPerspective(45, 16 / 9, 1, 1000);

      // Create a frustum shape that is represented by the matrix
      const frustum = new pc.Frustum();
      frustum.setFromMat4(projection);