#[cfg(feature = "extensions")]
use serde_json::{Map, Value};
use crate::{Accessor, Document, Node};
#[cfg(feature = "utils")]
use crate::Buffer;
pub mod iter;
#[cfg(feature = "utils")]
#[cfg_attr(docsrs, doc(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,
index,
json,
}
}
pub fn index(&self) -> usize {
self.index
}
#[cfg(feature = "extensions")]
#[cfg_attr(docsrs, doc(cfg(feature = "extensions")))]
pub fn extensions(&self) -> Option<&Map<String, Value>> {
let ext = self.json.extensions.as_ref()?;
Some(&ext.others)
}
#[cfg(feature = "extensions")]
#[cfg_attr(docsrs, doc(cfg(feature = "extensions")))]
pub fn extension_value(&self, ext_name: &str) -> Option<&Value> {
let ext = self.json.extensions.as_ref()?;
ext.others.get(ext_name)
}
pub fn extras(&self) -> &'a 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")]
#[cfg_attr(docsrs, doc(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")]
#[cfg_attr(docsrs, doc(cfg(feature = "names")))]
pub fn name(&self) -> Option<&'a str> {
self.json.name.as_deref()
}
pub fn skeleton(&self) -> Option<Node<'a>> {
self.json
.skeleton
.as_ref()
.map(|index| self.document.nodes().nth(index.value()).unwrap())
}
}