1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::*;
#[derive(Clone, Debug)]
pub struct PhysicsMaterial {
pub id: Option<String>,
pub name: Option<String>,
pub asset: Option<Box<Asset>>,
pub common: PhysicsMaterialCommon,
pub technique: Vec<Technique>,
pub extra: Vec<Extra>,
}
impl HasId for PhysicsMaterial {
fn id(&self) -> Option<&str> {
self.id.as_deref()
}
}
impl XNode for PhysicsMaterial {
const NAME: &'static str = "physics_material";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
Ok(PhysicsMaterial {
id: element.attr("id").map(Into::into),
name: element.attr("name").map(Into::into),
asset: Asset::parse_opt_box(&mut it)?,
common: parse_one(Technique::COMMON, &mut it, PhysicsMaterialCommon::parse)?,
technique: Technique::parse_list(&mut it)?,
extra: Extra::parse_many(it)?,
})
}
}
#[derive(Clone, Copy, Debug)]
pub struct PhysicsMaterialCommon {
pub dynamic_friction: f32,
pub restitution: f32,
pub static_friction: f32,
}
impl PhysicsMaterialCommon {
fn parse(e: &Element) -> Result<Self> {
let mut it = e.children().peekable();
let res = PhysicsMaterialCommon {
dynamic_friction: parse_opt("dynamic_friction", &mut it, parse_elem)?.unwrap_or(0.),
restitution: parse_opt("restitution", &mut it, parse_elem)?.unwrap_or(0.),
static_friction: parse_opt("static_friction", &mut it, parse_elem)?.unwrap_or(0.),
};
finish(res, it)
}
}