Compute a stable 64-bit content hash for the SDF input. Only position bits and indices feed in — meshes that share a surface but differ in normals/uv/colour share a cache entry, which is correct: SDF is geometry-only. `positions` is the contiguous `[f32; 3]` slice (one entry per vertex). Callers with an interleaved vertex stride extract just the position component before calling.
(positions: &[[f32; 3]], indices: &[u32])
| 68 | /// vertex). Callers with an interleaved vertex stride extract just |
| 69 | /// the position component before calling. |
| 70 | pub fn compute_mesh_hash(positions: &[[f32; 3]], indices: &[u32]) -> MeshHash { |
| 71 | let mut h: u64 = 0xcbf29ce484222325; |
| 72 | let mix = |h: &mut u64, b: u8| { |
| 73 | *h ^= b as u64; |
| 74 | *h = h.wrapping_mul(0x100000001b3); |
| 75 | }; |
| 76 | for p in positions { |
| 77 | for c in p { |
| 78 | for b in c.to_bits().to_le_bytes() { |
| 79 | mix(&mut h, b); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | for i in indices { |
| 84 | for b in i.to_le_bytes() { |
| 85 | mix(&mut h, b); |
| 86 | } |
| 87 | } |
| 88 | // Fold the vertex/index counts in so two meshes that share a |
| 89 | // prefix can't accidentally collide via positions-as-suffix. |
| 90 | for b in (positions.len() as u64).to_le_bytes() { |
| 91 | mix(&mut h, b); |
| 92 | } |
| 93 | for b in (indices.len() as u64).to_le_bytes() { |
| 94 | mix(&mut h, b); |
| 95 | } |
| 96 | let _ = fnv1a; // expose the helper for any future direct use |
| 97 | MeshHash(h) |
| 98 | } |
| 99 | |
| 100 | /// Platform cache root. Returns `None` when the host has no usable |
| 101 | /// cache directory (wasm) or when the env vars used to derive the |