frustum

Frustum culling for efficient 3D rendering.

This module provides both an object-oriented Frustum class for individual tests and a highly optimized, Numba-compiled vectorized function for testing thousands of chunks simultaneously against the camera’s view frustum.

class frustum.Frustum(camera)[source]

Bases: object

Calculates the camera’s viewing frustum planes and boundaries dynamically based on the Field of View and Aspect Ratio.

Parameters:

camera (Any) – The main camera instance tracking the player’s perspective.

update_factors(vertical_fov, horizontal_fov)[source]

Recalculate cached tangent/factor values from vertical and horizontal FOV.

Parameters:
  • vertical_fov (float) – Vertical field-of-view in radians.

  • horizontal_fov (float) – Horizontal field-of-view in radians.

Return type:

None

is_on_frustum(chunk)[source]

Determine whether the given chunk’s bounding sphere intersects the view frustum.

Parameters:

chunk (Any) – Object with a center attribute representing 3D position.

Returns:

True if the chunk is (partially) inside the camera frustum, False otherwise.

Return type:

bool

frustum.frustum_cull_fast(chunk_centers, out_mask, camera_position, camera_forward, camera_right, camera_up, tangent_y, tangent_x, factor_y, factor_x)[source]

Numba-optimized vectorized frustum culling.

Parameters:
  • chunk_centers (Any) – Nx3 array of chunk center coordinates.

  • out_mask (Any) – Preallocated boolean array that will be written with visibility flags.

  • camera_position (Any) – Camera position (3,) array.

  • camera_forward (Any) – Camera forward vector (3,) array.

  • camera_right (Any) – Camera right vector (3,) array.

  • camera_up (Any) – Camera up vector (3,) array.

  • tangent_y (float) – Tangent of half-vertical FOV.

  • tangent_x (float) – Tangent of half-horizontal FOV.

  • factor_y (float) – Precomputed vertical factor used for bounds checks.

  • factor_x (float) – Precomputed horizontal factor used for bounds checks.

Returns:

The out_mask array with booleans indicating visibility for each center.

Return type:

Any