live2d_parser/cubism_v1/moc/
pivots.rs

1use super::*;
2
3#[derive(Debug, Serialize, Deserialize)]
4pub struct PivotManager {
5    pub items: Vec<Pivot>,
6}
7
8#[derive(Debug, Serialize, Deserialize)]
9pub struct Pivot {
10    pub id: String,
11    pub count: u32,
12    pub values: Vec<f32>,
13}
14
15impl MocObject for PivotManager {
16    fn read_object(reader: &mut MocReader) -> Result<Self, L2Error>
17    where
18        Self: Sized,
19    {
20        let o: ObjectData = reader.read()?;
21        Ok(Self { items: o.as_pivots() })
22    }
23}
24
25impl MocObject for Pivot {
26    fn read_object(reader: &mut MocReader) -> Result<Self, L2Error>
27    where
28        Self: Sized,
29    {
30        let id = reader.read()?;
31        let count: i32 = reader.read()?;
32        let values: ObjectData = reader.read()?;
33        Ok(Self {
34            id,
35            count: count as u32,
36            // 似乎总是 f32[3], 暂未发现反例
37            values: values.as_f32_array(),
38        })
39    }
40}
41
42impl ObjectData {
43    pub fn as_pivots(self) -> Vec<Pivot> {
44        match self {
45            ObjectData::Null => Vec::new(),
46            ObjectData::ObjectArray(o) => o.into_iter().map(|x| x.as_pivots()).flatten().collect(),
47            ObjectData::Pivot(v) => vec![v],
48            ObjectData::PivotManager(v) => v.items,
49            s => {
50                warn!("ObjectData::as_pivots() called on non-pivot object {s:?}");
51                vec![]
52            }
53        }
54    }
55}