use {accessor, json, scene, Document};
#[cfg(feature = "utils")]
use Buffer;
pub use json::animation::{Interpolation, Property};
pub mod iter;
#[cfg(feature = "utils")]
pub mod util;
#[cfg(feature = "utils")]
#[doc(inline)]
pub use self::util::Reader;
#[derive(Clone, Debug)]
pub struct Animation<'a> {
document: &'a Document,
index: usize,
json: &'a json::animation::Animation,
}
#[derive(Clone, Debug)]
pub struct Channel<'a> {
anim: Animation<'a>,
json: &'a json::animation::Channel,
}
#[derive(Clone, Debug)]
pub struct Sampler<'a> {
anim: Animation<'a>,
json: &'a json::animation::Sampler,
}
#[derive(Clone, Debug)]
pub struct Target<'a> {
anim: Animation<'a>,
json: &'a json::animation::Target,
}
impl<'a> Animation<'a> {
pub(crate) fn new(
document: &'a Document, index: usize,
json: &'a json::animation::Animation,
) -> 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 channels(&self) -> iter::Channels<'a> {
iter::Channels {
anim: self.clone(),
iter: self.json.channels.iter(),
}
}
#[cfg(feature = "names")]
pub fn name(&self) -> Option<&str> {
self.json.name.as_ref().map(String::as_str)
}
pub fn samplers(&self) -> iter::Samplers<'a> {
iter::Samplers {
anim: self.clone(),
iter: self.json.samplers.iter(),
}
}
}
impl<'a> Channel<'a> {
pub(crate) fn new(
anim: Animation<'a>,
json: &'a json::animation::Channel,
) -> Self {
Self {
anim: anim,
json: json,
}
}
pub fn animation(&self) -> Animation<'a> {
self.anim.clone()
}
pub fn sampler(&self) -> Sampler<'a> {
self.anim.samplers().nth(self.json.sampler.value()).unwrap()
}
pub fn target(&self) -> Target<'a> {
Target::new(self.anim.clone(), &self.json.target)
}
#[cfg(feature = "utils")]
pub fn reader<'s, F>(&self, get_buffer_data: F) -> Reader<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
Reader {
channel: self.clone(),
get_buffer_data,
}
}
pub fn extras(&self) -> &json::Extras {
&self.json.extras
}
}
impl<'a> Target<'a> {
pub(crate) fn new(
anim: Animation<'a>,
json: &'a json::animation::Target,
) -> Self {
Self {
anim: anim,
json: json,
}
}
pub fn animation(&self) -> Animation<'a> {
self.anim.clone()
}
pub fn extras(&self) -> &json::Extras {
&self.json.extras
}
pub fn node(&self) -> scene::Node {
self.anim.document.nodes().nth(self.json.node.value()).unwrap()
}
pub fn property(&self) -> Property {
self.json.path.unwrap()
}
}
impl<'a> Sampler<'a> {
pub(crate) fn new(
anim: Animation<'a>,
json: &'a json::animation::Sampler,
) -> Self {
Self {
anim: anim,
json: json,
}
}
pub fn animation(&self) -> Animation<'a> {
self.anim.clone()
}
pub fn extras(&self) -> &json::Extras {
&self.json.extras
}
pub fn input(&self) -> accessor::Accessor<'a> {
self.anim.document.accessors().nth(self.json.input.value()).unwrap()
}
pub fn interpolation(&self) -> Interpolation {
self.json.interpolation.unwrap()
}
pub fn output(&self) -> accessor::Accessor<'a> {
self.anim.document.accessors().nth(self.json.output.value()).unwrap()
}
}