Skip to main content

unityrs_meshdecode/
owned.rs

1//! Owned handler arrays, with their original Python numeric types and charges.
2use crate::handler::IndexBuffer;
3use crate::unpack::VertexArray;
4use crate::vertex::Attributes;
5
6/// A processed mesh independent of its parsed source. Each buffer retains its charge.
7#[derive(Debug)]
8pub struct ProcessedOwned {
9    pub(crate) vertex_count: u64,
10    pub(crate) use_16bit: bool,
11    pub(crate) index_buffer: Option<IndexBuffer>,
12    pub(crate) attrs: Attributes,
13}
14const _: () = crate::send_sync::<ProcessedOwned>();
15impl ProcessedOwned {
16    /// `m_VertexCount`.
17    #[must_use]
18    pub fn vertex_count(&self) -> u64 {
19        self.vertex_count
20    }
21
22    /// `m_Use16BitIndices`.
23    #[must_use]
24    pub fn use_16bit_indices(&self) -> bool {
25        self.use_16bit
26    }
27
28    /// `m_IndexBuffer`: `None` where the source had none.
29    #[must_use]
30    pub fn index_buffer(&self) -> Option<&IndexBuffer> {
31        self.index_buffer.as_ref()
32    }
33
34    /// `m_Vertices`.
35    #[must_use]
36    pub fn vertices(&self) -> Option<&VertexArray> {
37        self.attrs.vertices.as_ref()
38    }
39
40    /// `m_Normals`.
41    #[must_use]
42    pub fn normals(&self) -> Option<&VertexArray> {
43        self.attrs.normals.as_ref()
44    }
45
46    /// `m_Tangents`.
47    #[must_use]
48    pub fn tangents(&self) -> Option<&VertexArray> {
49        self.attrs.tangents.as_ref()
50    }
51
52    /// `m_Colors`.
53    #[must_use]
54    pub fn colors(&self) -> Option<&VertexArray> {
55        self.attrs.colors.as_ref()
56    }
57
58    /// `m_UV0` to `m_UV7`: `uv(i)`, `None` past 7.
59    #[must_use]
60    pub fn uv(&self, i: usize) -> Option<&VertexArray> {
61        self.attrs.uv.get(i).and_then(Option::as_ref)
62    }
63
64    /// `m_BoneWeights`.
65    #[must_use]
66    pub fn bone_weights(&self) -> Option<&VertexArray> {
67        self.attrs.bone_weights.as_ref()
68    }
69
70    /// `m_BoneIndices`.
71    #[must_use]
72    pub fn bone_indices(&self) -> Option<&VertexArray> {
73        self.attrs.bone_indices.as_ref()
74    }
75
76    /// `m_BindPose`, which a compressed mesh below 5 sets: each matrix's
77    /// 16 `float`s flat, row by row, so a tuple of 16 (UnityPy's
78    /// `reshape(shape=(4, 4))` gives each as four rows of 4, the last
79    /// matrix's rows cut short, then empty, where the count is no multiple
80    /// of 16).
81    #[must_use]
82    pub fn bind_pose(&self) -> Option<&VertexArray> {
83        self.attrs.bind_pose.as_ref()
84    }
85}