Skip to main content

Module mesh

Module mesh 

Source
Expand description

Vertex compression and the per-mesh decode metadata.

The built-in pipeline consumes a compact vertex layout: positions and UVs are 16-bit normalized integers relative to a per-mesh bounding box, so the shader needs the parameters that reverse that encoding. MeshMetadata carries those parameters; compress_positions and compress_uvs produce them together with the packed attribute streams.

The Rust side and the WGSL side (mesh_metadata.wesl) are kept in sync by the crate. SecondaryStreamWriter and PositionStreamWriter pack the per-vertex streams a draw declares, whichever pipeline then draws them.

§One description per stream

A stream is described by StreamChannels: one attribute location and ChannelEncoding per channel, in the order the channels are interleaved. The pipeline’s vertex layout, the compression that packs a mesh and the streams a pool allocates all derive their bytes per vertex from that same description, so the three cannot drift apart.

Re-exports§

use wgpu::WriteOnly; 🔒

Structs§

JointPair
The joint indices and weights of one vertex, as the position stream stores them.
MeshInstance
One per-instance record: the affine model matrix, base color, pose bases, metadata index, alpha cutoff and inverted-hull width the built-in pipeline reads from its per-instance vertex buffer.
MeshMetadata
Per-mesh vertex-decode parameters and draw addressing.
PositionStreamChannels
The channels of the position vertex stream: a position and, for a skinned mesh, the joint indices and weights that deform it.
PositionStreamWriter
Packs the position vertex stream: the compressed position and, when the stream declares them, the joint indices and weights that deform it.
SecondaryFlags
The optional per-vertex channels of a secondary vertex stream: the UV, color and normal a mesh carries beside its position.
SecondaryStreamWriter
The optional per-vertex channels of a secondary vertex stream: the UV, color and normal that a mesh carries beside its position.
StreamChannels
The channels one per-vertex stream carries, in the order they are interleaved.

Enums§

ChannelEncoding
How one compressed channel is encoded as a vertex attribute.
CompressError
Failure reasons reported by the compression helpers.

Constants§

MAX_POSITION_STRIDE 🔒
Bytes per vertex of the widest position stream, used to size the per-vertex scratch the writer assembles on the stack.
MAX_SECONDARY_STRIDE 🔒
Bytes per vertex of the widest secondary stream, used to size the per-vertex scratch the writer assembles on the stack.

Functions§

compress_indices
Narrow u32 indices to u16.
compress_normals
Octahedral-encode normals into Snorm16x2 lanes.
compress_positions
Compress positions into Snorm16x4 relative to their bounding box, writing the decode parameters into out_meta.
compress_uvs
Compress UVs into Snorm16x2 remapped by their bounding box, writing the decode parameters into out_meta.uv_min_and_extents.
compress_weights
Quantize joint weights to Unorm16x4, clamping out-of-range components.
derive_position_bounds 🔒
Derive the position decode parameters from positions and write them into out_meta.
derive_uv_bounds 🔒
Derive the UV decode parameters from uvs and write them into out_meta.uv_min_and_extents.
encode_scale 🔒
The reciprocal of extents, with degenerate axes collapsed to zero.
encode_scale2 🔒
The 2D counterpart of encode_scale, for the UV range.
encode_uvs
The compressed UVs of uvs, encoded against out_meta’s existing parameters without re-deriving them.
f32_to_snorm16 🔒
Quantize [-1, 1] floats to signed 16-bit normalized integers.
f32_to_unorm8 🔒
Quantize one normalized f32 to Unorm8.
f32_to_unorm16 🔒
Quantize one normalized f32 to Unorm16.
index_fits_u16
Whether a vertex index can be named by a Uint16 index buffer.
octahedral_encode 🔒
Octahedral-encode a unit normal into two [-1, 1] lanes.
quantize_colors
Quantize [f32; 4] colors to Unorm8x4, clamping out-of-range components.
vertex_count_of 🔒
The vertex count a stream’s enabled channels agree on, or 0 for a stream with no channels.

Type Aliases§

CompressedColor
One vertex color: Unorm8x4, straight (non-premultiplied) linear RGBA.
CompressedJoints
One vertex’s joint indices: Uint16x4.
CompressedNormal
One compressed vertex normal: Snorm16x2, octahedral-encoded.
CompressedPosition
One compressed vertex position: Snorm16x4 relative to the mesh AABB.
CompressedUv
One compressed vertex UV: Snorm16x2 remapped by MeshMetadata::uv_min_and_extents.
CompressedWeights
One vertex’s joint weights: Unorm16x4, summing to 1.
JointMatrix
One joint’s skinning matrix: the joint’s transform times the inverse of the bind-pose transform, applied to a vertex in the mesh’s local space.