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
mod camera;
mod light;
pub mod model;
use crate::utils::*;
use crate::GltfData;
pub use camera::Camera;
pub use light::Light;
pub use model::{Material, Model};
use cgmath::*;
use gltf::scene::Node;
#[derive(Default, Clone, Debug)]
pub struct Scene {
pub models: Vec<Model>,
pub cameras: Vec<Camera>,
pub lights: Vec<Light>,
}
impl Scene {
pub(crate) fn load(gltf_scene: gltf::Scene, data: &GltfData, col: &mut Collection) -> Self {
let mut scene = Self::default();
for node in gltf_scene.nodes() {
scene.read_node(&node, &One::one(), data, col);
}
scene
}
fn read_node(
&mut self,
node: &Node,
parent_transform: &Matrix4<f32>,
data: &GltfData,
col: &mut Collection,
) {
let transform = parent_transform * transform_to_matrix(node.transform());
for child in node.children() {
self.read_node(&child, &transform, data, col);
}
if let Some(camera) = node.camera() {
self.cameras.push(Camera::load(camera, &transform));
}
if let Some(light) = node.light() {
self.lights.push(Light::load(light, &transform));
}
if let Some(mesh) = node.mesh() {
for primitive in mesh.primitives() {
self.models
.push(Model::load(primitive, &transform, data, col));
}
}
}
}