rhodonite
    Preparing search index...

    Class Frustum

    The view frustum class. Represents a truncated pyramid (frustum) used for view culling in 3D graphics. Contains six planes (top, bottom, left, right, near, far) and eight corner vertices.

    Index

    Constructors

    Properties

    bottom: MutableVector4 = ...
    corners: Vector4[] = []
    left: MutableVector4 = ...
    right: MutableVector4 = ...
    top: MutableVector4 = ...
    zFar: MutableVector4 = ...
    zNear: MutableVector4 = ...

    Methods

    • Performs frustum culling test against a mesh component's bounding box. Uses optimized frustum-AABB intersection algorithm to determine visibility.

      Parameters

      • meshComponent: MeshComponent

        The mesh component to test for culling

      Returns boolean

      false if the mesh is completely outside the frustum (should be culled), true if the mesh is inside or intersects the frustum (should be rendered)

      This method uses a two-phase approach:

      1. Tests if the AABB is completely outside any frustum plane
      2. Tests if all frustum corners are outside any AABB face

      The algorithm is based on the optimized frustum culling technique described at: https://iquilezles.org/articles/frustumcorrect/

      const frustum = new Frustum();
      frustum.update(viewMatrix, projectionMatrix);

      if (frustum.culling(meshComponent)) {
      // Render the mesh
      renderMesh(meshComponent);
      }
      // Otherwise, skip rendering (culled)
    • Retrieves a specific frustum plane by index.

      Parameters

      • i: number

        The plane index (0-5)

        • 0: Top plane
        • 1: Bottom plane
        • 2: Right plane
        • 3: Left plane
        • 4: Near plane
        • 5: Far plane

      Returns MutableVector4

      The plane as a Vector4 where (x,y,z) represents the plane normal and w represents the distance from the origin

      Throws an error if the plane index is invalid (not 0-5)

      const frustum = new Frustum();
      const topPlane = frustum.getPlane(0); // Get top plane
      const nearPlane = frustum.getPlane(4); // Get near plane
    • Updates this view frustum data from the view and projection matrices. Calculates the six frustum planes and eight corner vertices in world space. This method should be called whenever the camera's view or projection matrix changes.

      Parameters

      • viewMatrix: Matrix44

        The view matrix that transforms from world space to view space

      • projectionMatrix: Matrix44

        The projection matrix that transforms from view space to clip space

      Returns void

      The frustum planes are calculated using the combined view-projection matrix. Corner vertices are computed by transforming normalized device coordinates back to world space. The planes are stored as Vector4 where (x,y,z) is the normal and w is the distance from origin.