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
use super::{CreationProxy, traits::ToSimpleVao};
use crate::default_attribute_bindings;
use glin::{self, SimpleVao};
use rin_util::{Error, Result};
use rin_graphics::{Node, NodeRef, NodeMut};

pub struct Builder{
    pub(crate) gl: CreationProxy,
}

impl Builder{
    pub fn from_mesh<T, U, G>(&self, mesh: &G) -> Result<Object<SimpleVao<T>>>
        where G: ToSimpleVao<T,U>,
    {
        let vao = mesh.to_simple_vao(&self.gl, default_attribute_bindings(), glin::gl::STATIC_DRAW)
            .map_err(|err| Error::with_cause("Error creating vao from mesh", err))?;
        Ok(Object{
            geom: vao,
            node: Node::identity(),
        })
    }
}

/// A geometry usually as some kind of glin::Vao and a transformations expressed as a Node
pub struct Object<G>{
    geom: G,
    node: Node,
}

impl<G> Object<G>{
    pub fn new(geom: G) -> Object<G> {
        Object{
            geom,
            node: Node::identity(),
        }
    }

    pub fn geometry(&self) -> &G{
        &self.geom
    }
}

impl<G> NodeRef for Object<G>{
    fn node(&self) -> &Node {
        &self.node
    }
}

impl<G> NodeMut for Object<G>{
    fn node_mut(&mut self) -> &mut Node {
        &mut self.node
    }

    fn update_with_parent_parts(
        &mut self,
        parent_loc: Option<&Node>,
        parent_orientation: Option<&Node>,
        parent_scale: Option<&Node>) -> bool
    {
        self.node.update_with_parent_parts(parent_loc, parent_orientation, parent_scale)
    }
}