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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use crate::*;
#[derive(Clone, Debug)]
pub struct Camera {
pub id: Option<String>,
pub name: Option<String>,
pub asset: Option<Box<Asset>>,
pub optics: Optics,
pub imager: Option<Imager>,
pub extra: Vec<Extra>,
}
impl HasId for Camera {
fn id(&self) -> Option<&str> {
self.id.as_deref()
}
}
impl XNode for Camera {
const NAME: &'static str = "camera";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
Ok(Camera {
id: element.attr("id").map(Into::into),
name: element.attr("name").map(Into::into),
asset: Asset::parse_opt_box(&mut it)?,
optics: Optics::parse_one(&mut it)?,
imager: Imager::parse_opt(&mut it)?,
extra: Extra::parse_many(it)?,
})
}
}
#[derive(Clone, Debug)]
pub struct Imager {
pub technique: Vec<Technique>,
pub extra: Vec<Extra>,
}
impl XNode for Imager {
const NAME: &'static str = "imager";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
Ok(Imager {
technique: Technique::parse_list_n::<1>(&mut it)?,
extra: Extra::parse_many(it)?,
})
}
}
#[derive(Clone, Debug)]
pub struct Optics {
pub ty: ProjectionType,
pub technique: Vec<Technique>,
pub extra: Vec<Extra>,
}
impl XNode for Optics {
const NAME: &'static str = "optics";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
Ok(Optics {
ty: parse_one(Technique::COMMON, &mut it, |e| {
let mut it = e.children().peekable();
finish(parse_one_many(&mut it, ProjectionType::parse)?, it)
})?,
technique: Technique::parse_list(&mut it)?,
extra: Extra::parse_many(it)?,
})
}
}
#[derive(Clone, Debug)]
pub enum ProjectionType {
Orthographic(Orthographic),
Perspective(Perspective),
}
impl ProjectionType {
pub fn parse(e: &Element) -> Result<Option<Self>> {
match e.name() {
Orthographic::NAME => Ok(Some(Self::Orthographic(Orthographic::parse(e)?))),
Perspective::NAME => Ok(Some(Self::Perspective(Perspective::parse(e)?))),
_ => Ok(None),
}
}
}
#[derive(Clone, Debug)]
pub struct Orthographic {
pub xmag: Option<f32>,
pub ymag: Option<f32>,
pub extra: Vec<Extra>,
pub aspect_ratio: Option<f32>,
pub znear: f32,
pub zfar: f32,
}
impl XNode for Orthographic {
const NAME: &'static str = "orthographic";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
let res = Orthographic {
xmag: parse_opt("xmag", &mut it, parse_elem)?,
ymag: parse_opt("ymag", &mut it, parse_elem)?,
extra: Extra::parse_list(&mut it)?,
aspect_ratio: parse_opt("aspect_ratio", &mut it, parse_elem)?,
znear: parse_one("znear", &mut it, parse_elem)?,
zfar: parse_one("zfar", &mut it, parse_elem)?,
};
finish(res, it)
}
}
#[derive(Clone, Copy, Debug)]
pub struct Perspective {
pub xfov: Option<f32>,
pub yfov: Option<f32>,
pub aspect_ratio: Option<f32>,
pub znear: f32,
pub zfar: f32,
}
impl XNode for Perspective {
const NAME: &'static str = "perspective";
fn parse(element: &Element) -> Result<Self> {
debug_assert_eq!(element.name(), Self::NAME);
let mut it = element.children().peekable();
let res = Perspective {
xfov: parse_opt("xfov", &mut it, parse_elem)?,
yfov: parse_opt("yfov", &mut it, parse_elem)?,
aspect_ratio: parse_opt("aspect_ratio", &mut it, parse_elem)?,
znear: parse_one("znear", &mut it, parse_elem)?,
zfar: parse_one("zfar", &mut it, parse_elem)?,
};
finish(res, it)
}
}