Look up cached voxel bytes. Returns `Some(bytes)` only when the file exists, parses, and matches the expected magic + version + resolution + payload size. Any failure is silently treated as a miss — the caller falls through to the GPU bake.
(hash: MeshHash)
| 144 | /// resolution + payload size. Any failure is silently treated as a |
| 145 | /// miss — the caller falls through to the GPU bake. |
| 146 | pub fn load(hash: MeshHash) -> Option<Vec<u8>> { |
| 147 | let path = cache_path(hash)?; |
| 148 | let mut f = fs::File::open(&path).ok()?; |
| 149 | |
| 150 | let mut header = [0u8; 16]; |
| 151 | f.read_exact(&mut header).ok()?; |
| 152 | if header[..6] != FILE_MAGIC { return None; } |
| 153 | if header[6] != FILE_VERSION { return None; } |
| 154 | // header[7] reserved (alignment pad / future flags). |
| 155 | let res = u32::from_le_bytes(header[8..12].try_into().ok()?); |
| 156 | if res != VOXEL_RES { return None; } |
| 157 | // header[12..16] reserved. |
| 158 | |
| 159 | let mut bytes = Vec::with_capacity(VOXEL_BYTES); |
| 160 | f.read_to_end(&mut bytes).ok()?; |
| 161 | if bytes.len() != VOXEL_BYTES { return None; } |
| 162 | Some(bytes) |
| 163 | } |
| 164 | |
| 165 | /// Write voxel bytes for a mesh hash. Best-effort; an `Err` return |
| 166 | /// means the cache wasn't updated but rendering can continue. |