wow_wmo/
types.rs

1use std::fmt;
2
3/// A 4-byte chunk identifier (magic)
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct ChunkId(pub [u8; 4]);
6
7impl ChunkId {
8    /// Create a new chunk identifier from a 4-byte array
9    pub const fn new(array: [u8; 4]) -> Self {
10        Self(array)
11    }
12
13    /// Create a new chunk identifier from a static string
14    ///
15    /// # Panics
16    ///
17    /// Panics if the string is not exactly 4 bytes
18    pub const fn from_str(s: &str) -> Self {
19        assert!(s.len() == 4, "ChunkId must be exactly 4 bytes");
20        let bytes = s.as_bytes();
21        Self([bytes[0], bytes[1], bytes[2], bytes[3]])
22    }
23
24    /// Get the raw bytes of this chunk identifier
25    pub fn as_bytes(&self) -> &[u8; 4] {
26        &self.0
27    }
28}
29
30impl fmt::Display for ChunkId {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        // Convert to string if all bytes are ASCII printable, otherwise show hex
33        if self.0.iter().all(|&b| b.is_ascii_graphic()) {
34            write!(f, "{}", std::str::from_utf8(&self.0).unwrap_or("????"))
35        } else {
36            write!(
37                f,
38                "0x{:02X}{:02X}{:02X}{:02X}",
39                self.0[0], self.0[1], self.0[2], self.0[3]
40            )
41        }
42    }
43}
44
45/// Represents a 3D vector
46#[derive(Debug, Clone, Copy, PartialEq, Default)]
47pub struct Vec3 {
48    pub x: f32,
49    pub y: f32,
50    pub z: f32,
51}
52
53/// Represents a bounding box defined by min and max points
54#[derive(Debug, Clone, Copy, PartialEq)]
55pub struct BoundingBox {
56    pub min: Vec3,
57    pub max: Vec3,
58}
59
60/// Represents RGBA color
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
62pub struct Color {
63    pub r: u8,
64    pub g: u8,
65    pub b: u8,
66    pub a: u8,
67}