use json;
use {Accessor, Document, Node};
#[cfg(feature = "utils")]
use Buffer;
pub mod iter;
#[cfg(feature = "utils")]
pub mod util;
#[cfg(feature = "utils")]
#[doc(inline)]
pub use self::util::Reader;
#[derive(Clone, Debug)]
pub struct Skin<'a> {
document: &'a Document,
index: usize,
json: &'a json::skin::Skin,
}
impl<'a> Skin<'a> {
pub(crate) fn new(
document: &'a Document,
index: usize,
json: &'a json::skin::Skin,
) -> Self {
Self {
document: document,
index: index,
json: json,
}
}
pub fn index(&self) -> usize {
self.index
}
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.document
.accessors()
.nth(index.value())
.unwrap()
})
}
#[cfg(feature = "utils")]
pub fn reader<'s, F>(
&'a self,
get_buffer_data: F,
) -> Reader<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
Reader {
skin: self.clone(),
get_buffer_data,
}
}
pub fn joints(&self) -> iter::Joints<'a> {
iter::Joints {
document: self.document,
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.document.nodes().nth(index.value()).unwrap()
})
}
}