Architecture
This document describes the architecture of the Voxel Mesh Optimization Library. It outlines the design, major components, data flow, and key algorithms that enable the library to optimize voxel meshes by merging multiple voxel faces into a single, efficient mesh.
1. System Overview
The core goal of this library is to convert a chunk (a 3D grid of voxels) into a single optimized mesh for real-time rendering. The process is broken down into several main steps:
- Occlusion Processing: Determines visible voxel faces by identifying which faces are not obscured by neighboring voxels.
- Face Merging: Applies a 2D disjoint set algorithm on the extracted visible faces to merge adjacent faces with the same color into larger, contiguous faces.
- Mesh Generation: Uses the optimized face data to construct a triangle-based mesh, reducing the overall number of triangles that need to be rendered.
2. Major components
2.1 Voxel, Chunk, and Mesh Representations
- Voxel: A voxel represents a colored point, modeled as a cube. It lacks texture mapping and supports a single solid color.
- Chunk: A chunk is a rectangular grid of voxels defined by dimensions along the X, Y, and Z axes. Chunks may contain empty or semi-transparent voxels.
- Mesh: A mesh is a 3D construct composed of triangles, used for rendering objects in game engines and other applications.
2.2 Core Modules
- Occlusion Logic Module: Contains algorithms to determine which voxel faces are visible based on their adjacency to other voxels. This is critical for reducing unnecessary geometry in the final mesh.
- Disjoint Set Optimization Module: Implements a 2D disjoint set (union-find) algorithm to merge adjacent visible faces that share the same color into larger faces. This reduces the number of triangles in the mesh.
- Mesh Optimizer Interface: Defines the interface for mesh optimization. Implementations, such as the current disjoint set-based optimizer, adhere to this interface. This abstraction makes the library extensible and technology-agnostic.