rustial_engine/layers/
model_layer.rs1use crate::layer::{Layer, LayerId};
4use crate::models::ModelInstance;
5use std::any::Any;
6
7pub struct ModelLayer {
9 id: LayerId,
10 name: String,
11 visible: bool,
12 opacity: f32,
13 pub query_layer_id: Option<String>,
15 pub query_source_id: Option<String>,
17 pub instances: Vec<ModelInstance>,
19}
20
21impl ModelLayer {
22 pub fn new(name: impl Into<String>) -> Self {
24 Self {
25 id: LayerId::next(),
26 name: name.into(),
27 visible: true,
28 opacity: 1.0,
29 query_layer_id: None,
30 query_source_id: None,
31 instances: Vec::new(),
32 }
33 }
34
35 pub fn with_query_metadata(
37 mut self,
38 layer_id: impl Into<Option<String>>,
39 source_id: impl Into<Option<String>>,
40 ) -> Self {
41 self.query_layer_id = layer_id.into();
42 self.query_source_id = source_id.into();
43 self
44 }
45
46 pub fn set_query_metadata(&mut self, layer_id: Option<String>, source_id: Option<String>) {
48 self.query_layer_id = layer_id;
49 self.query_source_id = source_id;
50 }
51
52 pub fn add(&mut self, instance: ModelInstance) {
54 self.instances.push(instance);
55 }
56}
57
58impl Layer for ModelLayer {
59 fn id(&self) -> LayerId {
60 self.id
61 }
62
63 fn kind(&self) -> crate::layer::LayerKind {
64 crate::layer::LayerKind::Model
65 }
66
67 fn name(&self) -> &str {
68 &self.name
69 }
70
71 fn visible(&self) -> bool {
72 self.visible
73 }
74
75 fn set_visible(&mut self, visible: bool) {
76 self.visible = visible;
77 }
78
79 fn opacity(&self) -> f32 {
80 self.opacity
81 }
82
83 fn set_opacity(&mut self, opacity: f32) {
84 self.opacity = opacity.clamp(0.0, 1.0);
85 }
86
87 fn as_any(&self) -> &dyn Any {
88 self
89 }
90
91 fn as_any_mut(&mut self) -> &mut dyn Any {
92 self
93 }
94}