Skip to main content

vrm_runtime/
morph_target.rs

1/// The per-vertex deltas of one blend shape target (expression morph).
2///
3/// Position deltas are mandatory; normal and tangent deltas are optional
4/// (the runtime falls back to the base attributes when absent).
5#[derive(Debug, Clone)]
6pub struct MorphTarget {
7    position_deltas: Vec<[f32; 3]>,
8    normal_deltas: Option<Vec<[f32; 3]>>,
9    tangent_deltas: Option<Vec<[f32; 3]>>,
10}
11
12impl MorphTarget {
13    pub(crate) fn new(
14        position_deltas: Vec<[f32; 3]>,
15        normal_deltas: Option<Vec<[f32; 3]>>,
16        tangent_deltas: Option<Vec<[f32; 3]>>,
17    ) -> Self {
18        Self {
19            position_deltas,
20            normal_deltas,
21            tangent_deltas,
22        }
23    }
24
25    /// Returns the position delta for every base vertex.
26    pub fn position_deltas(&self) -> &[[f32; 3]] {
27        &self.position_deltas
28    }
29
30    /// Returns optional normal deltas aligned with the base vertices.
31    pub fn normal_deltas(&self) -> Option<&[[f32; 3]]> {
32        self.normal_deltas.as_deref()
33    }
34
35    /// Returns optional tangent deltas aligned with the base vertices.
36    pub fn tangent_deltas(&self) -> Option<&[[f32; 3]]> {
37        self.tangent_deltas.as_deref()
38    }
39}