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
}
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())
}
}