Skip to main content

Module mesh_section

Module mesh_section 

Source
Expand description

.10d QuantizedMesh section — the geometry half of a mesh asset in the container (P0.4).

A QuantizedMesh section wraps a Mesh as a self-describing .10d section. Vertex positions are quantized to u16 per axis within the mesh’s bounding box — 6 bytes/vertex vs 12 for raw f32 (2×), and the bbox is exactly what the semantic quins already carry, so it doubles as the dequantization frame (no information is invented). Triangle indices are u16 when the mesh has ≤65 536 vertices (6 bytes/tri vs 12). Quantization error is bbox_extent / 65535 per axis — sub-micron at organ scale, visually lossless.

Layout: a 40-byte MeshMiniHeader (flags + counts + dequantization bbox + reserved) followed by the quantized vertex data (N × 6 bytes: u16×3 per vertex) and then the triangle indices (u16×3 or u32×3 per triangle, selected by the FLAG_U16_INDICES flag). The mini-header is repr(C), naturally aligned, no implicit padding.

This replaces the erroneous legacy mesh build artifact that lived in render/mesh_asset.rs — a pre-release format that was never shipped and has been refactored out rather than carried forward. The legacy 48-byte header with its per-format magic is gone; the .10d section-type tag (SectionType::QuantizedMesh = 1) replaces the magic, and the .10d container version replaces the per-format version. No backward-compat is provided — the legacy format was an erroneous build artifact, not a shipped format anyone depends on.

Determinism + CRC: two encodes of the same mesh are byte-identical (the quantization is deterministic). The per-section CRC-32C (P0.2) catches a flipped bit in the payload. The whole-file CRC-32C (P0.3) catches header corruption.

Structs§

MeshMiniHeader
The 40-byte QuantizedMesh-section mini-header. repr(C), naturally aligned, no implicit padding.

Enums§

MeshSectionError
Mesh-section read/write error.

Constants§

FLAG_U16_INDICES
flags bit 0: triangle indices are u16 (else u32).
MAX_TRIANGLE_COUNT
Maximum triangle count. Similarly bounded by the Sentinel: 40MB / 6 bytes per u16-indexed triangle ≈ 6.7M triangles. 4M is the matching ceiling.
MAX_VERTEX_COUNT
Maximum vertex count the mesh section will accept. Bounds against a hostile/malformed file. u16 indices cap at 65 536; above that the encoder switches to u32. The practical ceiling is the 42MB Sentinel: 40MB of vertex data / 6 bytes per vertex ≈ 6.7M vertices. 4M (2^22) is a comfortable upper bound.
MESH_MINI_HEADER_SIZE
Section payload mini-header size in bytes.

Functions§

decode_mesh_section
Decode a .10d QuantizedMesh section payload back into a Mesh (dequantized positions, exact indices). This is the ingest path (not a hot path), so Vec allocation is fine per AGENTS.md §2-B.
encode_mesh_section
Encode a Mesh into a .10d QuantizedMesh section payload in a caller-supplied buffer. Returns the bytes written. Zero-heap. The bbox is recomputed from the positions (independent of any stale mesh.min/max) so it is a faithful dequantization frame.
encoded_len
Encoded length in bytes for a mesh of the given size (for size reporting without allocating).
fits_u16_indices
Whether a mesh with vertex_count vertices can use u16 indices.
parse_mesh_header
Parse and validate the mesh-section mini-header. Returns the header and the total payload byte length it claims.
raw_geometry_len
Raw in-memory geometry size (f32 positions + u32 triangle indices) — the baseline we shrink from.