live2d_parser/cubism_v1/moc/
parts.rs1use super::*;
2
3#[derive(Debug, Serialize, Deserialize)]
4pub struct Part {
5 pub id: String,
7 pub flags: u8,
9 pub deformers: ObjectData,
10 pub components: ObjectData,
11}
12
13#[derive(Debug)]
14pub enum PartType {
15 Normal,
17 Mesh,
19}
20
21impl MocObject for Part {
22 fn read_object(r: &mut MocReader) -> Result<Self, L2Error>
23 where
24 Self: Sized,
25 {
26 let flags = r.read()?;
27 let name = r.read()?;
28 let deformers = r.read()?;
29 let components = r.read()?;
30 Ok(Self { deformers, id: name, components, flags })
31 }
32}
33
34impl Part {
35 pub fn is_locked(&self) -> bool {
36 self.flags & 0x01 != 0
37 }
38 pub fn is_visible(&self) -> bool {
39 self.flags & 0x02 != 0
40 }
41}
42
43impl ObjectData {
44 pub fn as_parts(self) -> Vec<Part> {
45 match self {
46 ObjectData::Part(v) => {
47 vec![*v]
48 }
49 ObjectData::ObjectArray(v) => v.into_iter().map(|o| o.as_parts()).flatten().collect(),
50 s => {
51 warn!("ObjectData::as_parts() called on non-pivot object {s:?}");
52 vec![]
53 }
54 }
55 }
56}