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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use cgmath;
use froggy;
use mint;
use hub::SubNode;
use material::Material;
use std::marker::PhantomData;
pub(crate) type NodePointer = froggy::Pointer<NodeInternal>;
pub(crate) type TransformInternal = cgmath::Decomposed<cgmath::Vector3<f32>, cgmath::Quaternion<f32>>;
#[derive(Debug)]
pub(crate) struct NodeInternal {
pub(crate) visible: bool,
pub(crate) transform: TransformInternal,
pub(crate) world_transform: TransformInternal,
pub(crate) next_sibling: Option<NodePointer>,
pub(crate) sub_node: SubNode,
}
impl NodeInternal {
pub(crate) fn to_node(&self) -> Node<Local> {
Node {
transform: self.transform.into(),
visible: self.visible,
material: match self.sub_node {
SubNode::Visual(ref mat, _, _) => Some(mat.clone()),
_ => None,
},
_space: PhantomData,
}
}
}
impl From<SubNode> for NodeInternal {
fn from(sub: SubNode) -> Self {
NodeInternal {
visible: true,
transform: cgmath::Transform::one(),
world_transform: cgmath::Transform::one(),
next_sibling: None,
sub_node: sub,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Transform {
pub position: mint::Point3<f32>,
pub orientation: mint::Quaternion<f32>,
pub scale: f32,
}
impl From<TransformInternal> for Transform {
fn from(tf: TransformInternal) -> Self {
let pos: mint::Vector3<f32> = tf.disp.into();
Transform {
position: pos.into(),
orientation: tf.rot.into(),
scale: tf.scale,
}
}
}
pub enum Local {}
pub enum World {}
#[derive(Clone, Debug, PartialEq)]
pub struct Node<Space> {
pub visible: bool,
pub transform: Transform,
pub material: Option<Material>,
pub(crate) _space: PhantomData<Space>,
}