1use std::collections::BTreeMap;
2use std::path::PathBuf;
3
4use crate::Diagnostic;
5use crate::types::{
6 Camera, Content, Emitter, Finish, FinishKeys, Haze, Light, Material, Mesh, Mover, Object,
7 Physics, Plates, Proxy, Rig, Sky, Sound, Sun, Text, Tiles, Trace,
8};
9
10#[derive(Clone, Debug, PartialEq)]
11pub struct Entry<T> {
12 pub key: String,
13 pub id: Option<String>,
14 pub file: PathBuf,
15 pub value: T,
16}
17
18#[derive(Clone, Debug, Default, PartialEq)]
19pub struct Scene {
20 pub path: PathBuf,
21 pub files: Vec<PathBuf>,
22 pub materials: Vec<Entry<Material>>,
23 pub fallback: Option<String>,
24 pub meshes: Vec<Entry<Mesh>>,
25 pub objects: Vec<Entry<Object>>,
26 pub lights: Vec<Entry<Light>>,
27 pub emitters: Vec<Entry<Emitter>>,
28 pub movers: Vec<Entry<Mover>>,
29 pub contents: Vec<Entry<Content>>,
30 pub texts: Vec<Entry<Text>>,
31 pub sounds: Vec<Entry<Sound>>,
32 pub rigs: Vec<Entry<Rig>>,
33 pub tiles: Vec<Entry<Tiles>>,
34 pub sun: Option<Sun>,
35 pub sky: Option<Sky>,
36 pub haze: Option<Haze>,
37 pub camera: Option<Camera>,
38 pub finish: Option<Finish>,
39 pub finish_file: Option<FinishKeys>,
40 pub trace: Option<Trace>,
41 pub plates: Option<Plates>,
42 pub proxies: Vec<Entry<Proxy>>,
43 pub physics: Option<Physics>,
44 pub layers: BTreeMap<String, Vec<String>>,
45 pub warnings: Vec<Diagnostic>,
46}
47
48fn find<'a, T>(entries: &'a [Entry<T>], key: &str) -> Option<&'a Entry<T>> {
49 entries.iter().find(|entry| entry.key == key)
50}
51
52impl Scene {
53 pub fn material(&self, key: &str) -> Option<&Entry<Material>> {
54 find(&self.materials, key)
55 }
56
57 pub fn mesh(&self, key: &str) -> Option<&Entry<Mesh>> {
58 find(&self.meshes, key)
59 }
60
61 pub fn object(&self, key: &str) -> Option<&Entry<Object>> {
62 find(&self.objects, key)
63 }
64
65 pub fn light(&self, key: &str) -> Option<&Entry<Light>> {
66 find(&self.lights, key)
67 }
68
69 pub fn emitter(&self, key: &str) -> Option<&Entry<Emitter>> {
70 find(&self.emitters, key)
71 }
72
73 pub fn mover(&self, key: &str) -> Option<&Entry<Mover>> {
74 find(&self.movers, key)
75 }
76
77 pub fn content(&self, key: &str) -> Option<&Entry<Content>> {
78 find(&self.contents, key)
79 }
80
81 pub fn text(&self, key: &str) -> Option<&Entry<Text>> {
82 find(&self.texts, key)
83 }
84
85 pub fn sound(&self, key: &str) -> Option<&Entry<Sound>> {
86 find(&self.sounds, key)
87 }
88
89 pub fn rig(&self, key: &str) -> Option<&Entry<Rig>> {
90 find(&self.rigs, key)
91 }
92
93 pub fn tile_layer(&self, key: &str) -> Option<&Entry<Tiles>> {
94 find(&self.tiles, key)
95 }
96}