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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use gltf_derive::Validate;
use serde_derive::{Serialize, Deserialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
pub struct Node {
#[cfg(feature = "KHR_lights_punctual")]
#[serde(default, rename = "KHR_lights_punctual", skip_serializing_if = "Option::is_none")]
pub khr_lights_punctual: Option<khr_lights_punctual::KhrLightsPunctual>,
}
#[cfg(feature = "KHR_lights_punctual")]
pub mod khr_lights_punctual {
use crate::{Extras, Index, Root, Path};
use crate::validation::{Checked, Error, Validate};
use gltf_derive::Validate;
use serde::{de, ser};
use serde_derive::{Deserialize, Serialize};
use std::fmt;
pub const VALID_TYPES: &'static [&'static str] = &[
"directional",
"point",
"spot",
];
#[derive(Clone, Debug, Deserialize, Serialize, Validate)]
pub struct KhrLightsPunctual {
pub light: Index<Light>,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Type {
Directional = 1,
Point,
Spot,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Light {
#[serde(default = "color_default")]
pub color: [f32; 3],
#[serde(default, skip_serializing_if = "Option::is_none")]
pub extensions: Option<std::boxed::Box<serde_json::value::RawValue>>,
#[serde(default)]
#[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))]
pub extras: Extras,
#[serde(default = "intensity_default")]
pub intensity: f32,
#[cfg(feature = "names")]
#[cfg_attr(feature = "names", serde(skip_serializing_if = "Option::is_none"))]
pub name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub range: Option<f32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub spot: Option<Spot>,
#[serde(rename = "type")]
pub type_: Checked<Type>,
}
impl Validate for Light {
fn validate<P, R>(&self, root: &Root, path: P, report: &mut R)
where P: Fn() -> Path, R: FnMut(&dyn Fn() -> Path, Error)
{
if let Checked::Valid(ty) = self.type_.as_ref() {
if *ty == Type::Spot && self.spot.is_none() {
report(&|| path().field("spot"), Error::Missing);
}
}
self.type_.validate(root, || path().field("type"), report);
self.extensions.validate(root, || path().field("extensions"), report);
self.extras.validate(root, || path().field("extras"), report);
}
}
fn color_default() -> [f32; 3] {
[1.0, 1.0, 1.0]
}
fn intensity_default() -> f32 {
1.0
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
#[serde(rename_all = "camelCase")]
pub struct Spot {
#[serde(default)]
pub inner_cone_angle: f32,
#[serde(default = "outer_cone_angle_default")]
pub outer_cone_angle: f32,
}
fn outer_cone_angle_default() -> f32 {
0.7853981633974483
}
impl<'de> de::Deserialize<'de> for Checked<Type> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
type Value = Checked<Type>;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "any of: {:?}", VALID_TYPES)
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where E: de::Error
{
use self::Type::*;
use crate::validation::Checked::*;
Ok(match value {
"directional" => Valid(Directional),
"point" => Valid(Point),
"spot" => Valid(Spot),
_ => Invalid,
})
}
}
deserializer.deserialize_str(Visitor)
}
}
impl ser::Serialize for Type {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer
{
serializer.serialize_str(match *self {
Type::Directional => "directional",
Type::Point => "point",
Type::Spot => "spot",
})
}
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
pub struct Scene {}