pub const MESHLET_DESCRIPTOR_STRIDE: usize = 4;
pub const MESHLET_BOUNDS_STRIDE: usize = 16;
pub const MESHLET_SCHEMA_VERSION: u32 = 1;
pub const MESHLET_MAX_VERTICES_LIMIT: u32 = 64;
pub const MESHLET_MAX_TRIANGLES_LIMIT: u32 = 126;
pub const SOURCE_VERTICES_BUDGET: u64 = 16_777_216;
pub const SOURCE_TRIANGLES_BUDGET: u64 = 4_000_000;
pub const OUTPUT_MESHLETS_BUDGET: u64 = 4_000_000;
pub const OUTPUT_TRIANGLE_BUDGET_DEFAULT: u64 = 8_000_000;
#[derive(Debug, Clone)]
pub struct IndexedGeometry {
pub positions: Vec<f32>,
pub indices: Vec<u32>,
}
impl IndexedGeometry {
#[must_use]
pub fn vertex_count(&self) -> usize {
self.positions.len() / 3
}
#[must_use]
pub fn triangle_count(&self) -> usize {
self.indices.len() / 3
}
}
#[derive(Debug, Default)]
pub(crate) struct PendingMeshlet {
local_by_global: rustc_hash_lite::FxHashMap<u32, u32>,
pub(crate) vertices: Vec<u32>,
pub(crate) triangles: Vec<u32>,
pub(crate) normals: Vec<[f64; 3]>,
pub(crate) has_degenerate: bool,
}
impl PendingMeshlet {
pub(crate) fn new() -> Self {
Self::default()
}
#[inline]
pub(crate) fn contains_global(&self, global: u32) -> bool {
self.local_by_global.contains_key(&global)
}
pub(crate) fn local_vertex(&mut self, global: u32) -> u32 {
if let Some(&existing) = self.local_by_global.get(&global) {
return existing;
}
let local = self.vertices.len() as u32;
self.local_by_global.insert(global, local);
self.vertices.push(global);
local
}
}
pub(crate) mod rustc_hash_lite {
#[derive(Default)]
pub(crate) struct FxHasher(u64);
impl std::hash::Hasher for FxHasher {
#[inline]
fn write_u32(&mut self, v: u32) {
self.0 = (self.0.rotate_left(5) ^ u64::from(v)).wrapping_mul(0x517c_c1b7_2722_0a95);
}
#[inline]
fn write_usize(&mut self, v: usize) {
self.write_u64(v as u64);
}
#[inline]
fn write_u64(&mut self, v: u64) {
self.0 = (self.0.rotate_left(5) ^ v).wrapping_mul(0x517c_c1b7_2722_0a95);
}
#[inline]
fn write(&mut self, bytes: &[u8]) {
for &b in bytes {
self.0 = (self.0.rotate_left(5) ^ u64::from(b)).wrapping_mul(0x517c_c1b7_2722_0a95);
}
}
#[inline]
fn finish(&self) -> u64 {
self.0
}
}
pub(crate) type FxHashMap<K, V> = std::collections::HashMap<K, V, std::hash::BuildHasherDefault<FxHasher>>;
pub(crate) type FxHashSet<K> = std::collections::HashSet<K, std::hash::BuildHasherDefault<FxHasher>>;
}