1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
//! Utility functions for glTF → GR2 conversion. //! //! Re-exports shared utilities from the parent module, plus GR2-specific functions. pub(crate) use crate::converter::gr2_gltf::shared::{encode_qtangent, f32_to_half}; /// Calculate CRC32 checksum (GR2 uses standard CRC-32) #[must_use] pub fn crc32(data: &[u8]) -> u32 { const TABLE: [u32; 256] = { let mut table = [0u32; 256]; let mut i = 0u32; while i < 256 { let mut crc = i; let mut j = 0; while j < 8 { if crc & 1 != 0 { crc = (crc >> 1) ^ 0xEDB88320; } else { crc >>= 1; } j += 1; } table[i as usize] = crc; i += 1; } table }; let mut crc = 0xFFFFFFFFu32; for &byte in data { crc = TABLE[((crc ^ u32::from(byte)) & 0xFF) as usize] ^ (crc >> 8); } !crc }