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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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) name: Option<String>,
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,
name: self.name.clone(),
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,
name: None,
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 Transform {
pub fn new() -> Transform {
Default::default()
}
}
impl Default for Transform {
fn default() -> Self {
Transform {
position: [0.0, 0.0, 0.0].into(),
orientation: [0.0, 0.0, 0.0, 1.0].into(),
scale: 1.0,
}
}
}
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,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Local {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum World {}
#[derive(Clone, Debug, PartialEq)]
pub struct Node<Space> {
pub visible: bool,
pub name: Option<String>,
pub transform: Transform,
pub material: Option<Material>,
pub(crate) _space: PhantomData<Space>,
}