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
use std::ops::Deref;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct VertexAttribute<T> {
pub(crate) data: Vec<T>,
pub(crate) attribute_size: u8,
}
impl<T> Deref for VertexAttribute<T> {
type Target = Vec<T>;
fn deref(&self) -> &Self::Target {
&self.data
}
}
#[cfg(test)]
impl<T> From<(Vec<T>, u8)> for VertexAttribute<T> {
fn from(v: (Vec<T>, u8)) -> Self {
VertexAttribute {
data: v.0,
attribute_size: v.1,
}
}
}
impl<T> VertexAttribute<T> {
pub fn new(data: Vec<T>, attribute_size: u8) -> Result<VertexAttribute<T>, ()> {
if attribute_size as usize % data.len() != 0 {
}
Ok(VertexAttribute {
data,
attribute_size,
})
}
#[allow(missing_docs)]
pub fn as_slice(&self) -> &[T] {
&self.data[..]
}
pub fn attribute_size(&self) -> u8 {
self.attribute_size
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct BoneAttributes {
pub(crate) bone_influencers: VertexAttribute<u8>,
pub(crate) bone_weights: VertexAttribute<f32>,
}
impl<T> VertexAttribute<T> {
pub fn data(&self) -> &Vec<T> {
&self.data
}
}
impl<T> VertexAttribute<T> {
pub(crate) fn data_at_idx(&self, vertex_idx: u16) -> &[T] {
let attribute_size = self.attribute_size as usize;
let idx = (vertex_idx as usize) * attribute_size;
&self.data[idx..idx + attribute_size]
}
}