three_d/renderer/object/
gm.rs1use crate::renderer::*;
2
3pub struct Gm<G: Geometry, M: Material> {
9 pub geometry: G,
11 pub material: M,
13}
14
15impl<G: Geometry, M: Material> Gm<G, M> {
16 pub fn new(geometry: G, material: M) -> Self {
20 Self { geometry, material }
21 }
22}
23
24impl<'a, G: Geometry, M: Material> IntoIterator for &'a Gm<G, M> {
25 type Item = &'a dyn Object;
26 type IntoIter = std::iter::Once<&'a dyn Object>;
27
28 fn into_iter(self) -> Self::IntoIter {
29 std::iter::once(self)
30 }
31}
32
33impl<G: Geometry + Clone, M: Material + Clone> Clone for Gm<G, M> {
34 fn clone(&self) -> Self {
35 Self {
36 geometry: self.geometry.clone(),
37 material: self.material.clone(),
38 }
39 }
40}
41
42use std::ops::Deref;
43impl<G: Geometry, M: Material> std::ops::Deref for Gm<G, M> {
44 type Target = G;
45 fn deref(&self) -> &Self::Target {
46 &self.geometry
47 }
48}
49
50impl<G: Geometry, M: Material> std::ops::DerefMut for Gm<G, M> {
51 fn deref_mut(&mut self) -> &mut Self::Target {
52 &mut self.geometry
53 }
54}
55
56impl<G: Geometry, M: Material> Geometry for Gm<G, M> {
57 impl_geometry_body!(deref);
58
59 fn animate(&mut self, time: f32) {
60 self.geometry.animate(time)
61 }
62}
63
64impl<G: Geometry, M: Material> Object for Gm<G, M> {
65 fn render(&self, viewer: &dyn Viewer, lights: &[&dyn Light]) {
66 self.render_with_material(&self.material, viewer, lights)
67 }
68
69 fn material_type(&self) -> MaterialType {
70 self.material.material_type()
71 }
72}