ogawa_rs/schemas/
xform_schema.rs1use crate::object_reader::ObjectReader;
2use crate::pod::*;
3use crate::property::*;
4use crate::reader::ArchiveReader;
5use crate::result::*;
6use crate::Archive;
7
8#[derive(Debug)]
9pub struct XformSchema {
10 pub child_bounds: Option<ScalarPropertyReader>,
11 pub arb_geometry_parameters: Option<CompoundPropertyReader>,
12 pub user_properties: Option<CompoundPropertyReader>,
13 pub is_constant_identity: bool,
14 pub is_constant: bool,
15}
16
17impl XformSchema {
18 pub fn new_from_object_reader(
19 object: &ObjectReader,
20 reader: &mut dyn ArchiveReader,
21 archive: &Archive,
22 ) -> Result<Self> {
23 let properties = object
24 .properties()
25 .ok_or(ParsingError::IncompatibleSchema)?;
26 let properties: CompoundPropertyReader = properties
27 .load_sub_property(0, reader, archive)?
28 .try_into()?;
29
30 let child_bounds = properties
31 .load_sub_property_by_name_checked(".childBnds", reader, archive, Some(&BOX_TYPE))?
32 .map(|x| x.try_into())
33 .transpose()?;
34
35 let inherits: Option<ScalarPropertyReader> = properties
36 .load_sub_property_by_name_checked(".inherits", reader, archive, Some(&BOOL_TYPE))?
37 .map(|x| x.try_into())
38 .transpose()?;
39
40 let vals = properties
41 .load_sub_property_by_name(".vals", reader, archive)?
42 .map(|x| {
43 let _data_type = match &x {
44 PropertyReader::Array(r) => &r.header.data_type,
45 PropertyReader::Scalar(r) => &r.header.data_type,
46 _ => return Err(ParsingError::IncompatibleSchema),
47 };
48
49 Ok(x)
53 })
54 .transpose()?;
55
56 let is_constant_identity = properties
57 .find_sub_property_index("isNotConstantIdentity")
58 .is_none();
59
60 let is_constant = if let Some(vals) = &vals {
61 match vals {
62 PropertyReader::Array(r) => r.is_constant(),
63 PropertyReader::Scalar(r) => r.is_constant(),
64 _ => return Err(ParsingError::IncompatibleSchema.into()),
65 }
66 } else {
67 true
68 };
69
70 let is_constant = is_constant
71 && if let Some(inherits) = &inherits {
72 inherits.is_constant()
73 } else {
74 true
75 };
76
77 let arb_geometry_parameters = properties
109 .load_sub_property_by_name(".arbGeomParams", reader, archive)?
110 .map(|x| -> Result<CompoundPropertyReader> { Ok(x.try_into()?) })
111 .transpose()?;
112
113 let user_properties = properties
114 .load_sub_property_by_name(".userProperties", reader, archive)?
115 .map(|x| -> Result<CompoundPropertyReader> { Ok(x.try_into()?) })
116 .transpose()?;
117
118 Ok(Self {
119 child_bounds,
120 is_constant_identity,
121 is_constant,
122 arb_geometry_parameters,
123 user_properties,
124 })
125 }
126
127 pub fn is_constant(&self) -> bool {
128 self.is_constant
129 }
130 pub fn is_constant_identity(&self) -> bool {
131 self.is_constant_identity
132 }
133}