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
use json;
use std::slice;
use {Accessor, Gltf, Node};
#[derive(Clone, Debug)]
pub struct Skin<'a> {
gltf: &'a Gltf,
index: usize,
json: &'a json::skin::Skin,
}
#[derive(Clone, Debug)]
pub struct Joints<'a> {
gltf: &'a Gltf,
iter: slice::Iter<'a, json::Index<json::scene::Node>>,
}
impl<'a> Skin<'a> {
pub(crate) fn new(
gltf: &'a Gltf,
index: usize,
json: &'a json::skin::Skin,
) -> Self {
Self {
gltf: gltf,
index: index,
json: json,
}
}
pub fn index(&self) -> usize {
self.index
}
#[doc(hidden)]
pub fn as_json(&self) -> &json::skin::Skin {
self.json
}
pub fn extras(&self) -> &json::Extras {
&self.json.extras
}
pub fn inverse_bind_matrices(&self) -> Option<Accessor<'a>> {
self.json.inverse_bind_matrices
.as_ref()
.map(|index| {
self.gltf
.accessors()
.nth(index.value())
.unwrap()
})
}
pub fn joints(&self) -> Joints<'a> {
Joints {
gltf: self.gltf,
iter: self.json.joints.iter(),
}
}
#[cfg(feature = "names")]
pub fn name(&self) -> Option<&str> {
self.json.name.as_ref().map(String::as_str)
}
pub fn skeleton(&self) -> Option<Node<'a>> {
self.json.skeleton.as_ref().map(|index| {
self.gltf.nodes().nth(index.value()).unwrap()
})
}
}
impl<'a> Iterator for Joints<'a> {
type Item = Node<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter
.next()
.map(|index| self.gltf.nodes().nth(index.value()).unwrap())
}
}