pub mod rotations;
pub mod morph_target_weights;
use accessor;
use animation::Channel;
use Buffer;
pub type ReadInputs<'a> = accessor::Iter<'a, f32>;
pub type Translations<'a> = accessor::Iter<'a, [f32; 3]>;
pub type Scales<'a> = accessor::Iter<'a, [f32; 3]>;
#[derive(Clone, Debug)]
pub struct Reader<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
pub(crate) channel: Channel<'a>,
pub(crate) get_buffer_data: F,
}
#[derive(Clone, Debug)]
pub enum Rotations<'a> {
I8(accessor::Iter<'a, [i8; 4]>),
U8(accessor::Iter<'a, [u8; 4]>),
I16(accessor::Iter<'a, [i16; 4]>),
U16(accessor::Iter<'a, [u16; 4]>),
F32(accessor::Iter<'a, [f32; 4]>),
}
#[derive(Clone, Debug)]
pub enum MorphTargetWeights<'a> {
I8(accessor::Iter<'a, i8>),
U8(accessor::Iter<'a, u8>),
I16(accessor::Iter<'a, i16>),
U16(accessor::Iter<'a, u16>),
F32(accessor::Iter<'a, f32>),
}
pub enum ReadOutputs<'a> {
Translations(Translations<'a>),
Rotations(Rotations<'a>),
Scales(Scales<'a>),
MorphTargetWeights(MorphTargetWeights<'a>),
}
impl<'a> Rotations<'a> {
pub fn into_i8(self) -> rotations::CastingIter<'a, rotations::I8> {
rotations::CastingIter::new(self)
}
pub fn into_u8(self) -> rotations::CastingIter<'a, rotations::U8> {
rotations::CastingIter::new(self)
}
pub fn into_i16(self) -> rotations::CastingIter<'a, rotations::I16> {
rotations::CastingIter::new(self)
}
pub fn into_u16(self) -> rotations::CastingIter<'a, rotations::U16> {
rotations::CastingIter::new(self)
}
pub fn into_f32(self) -> rotations::CastingIter<'a, rotations::F32> {
rotations::CastingIter::new(self)
}
}
impl<'a> MorphTargetWeights<'a> {
pub fn into_i8(self) -> morph_target_weights::CastingIter<'a, morph_target_weights::I8> {
morph_target_weights::CastingIter::new(self)
}
pub fn into_u8(self) -> morph_target_weights::CastingIter<'a, morph_target_weights::U8> {
morph_target_weights::CastingIter::new(self)
}
pub fn into_i16(self) -> morph_target_weights::CastingIter<'a, morph_target_weights::I16> {
morph_target_weights::CastingIter::new(self)
}
pub fn into_u16(self) -> morph_target_weights::CastingIter<'a, morph_target_weights::U16> {
morph_target_weights::CastingIter::new(self)
}
pub fn into_f32(self) -> morph_target_weights::CastingIter<'a, morph_target_weights::F32> {
morph_target_weights::CastingIter::new(self)
}
}
impl<'a, 's, F> Reader<'a, 's, F>
where F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
pub fn read_inputs(&self) -> Option<ReadInputs<'s>> {
let buffer = self.channel.sampler().input().view().buffer();
if let Some(slice) = (self.get_buffer_data)(buffer) {
Some(accessor::Iter::new(self.channel.sampler().input(), slice))
} else {
None
}
}
pub fn read_outputs(&self) -> Option<ReadOutputs<'s>> {
use accessor::{DataType, Iter};
use animation::Property;
let output = self.channel.sampler().output();
if let Some(slice) = (self.get_buffer_data)(output.view().buffer()) {
Some(
match self.channel.target().property() {
Property::Translation => ReadOutputs::Translations(Iter::new(output, slice)),
Property::Rotation => ReadOutputs::Rotations(match output.data_type() {
DataType::I8 => Rotations::I8(Iter::new(output, slice)),
DataType::U8 => Rotations::U8(Iter::new(output, slice)),
DataType::I16 => Rotations::I16(Iter::new(output, slice)),
DataType::U16 => Rotations::U16(Iter::new(output, slice)),
DataType::F32 => Rotations::F32(Iter::new(output, slice)),
_ => unreachable!()
}),
Property::Scale => ReadOutputs::Scales(Iter::new(output, slice)),
Property::MorphTargetWeights => ReadOutputs::MorphTargetWeights(match output.data_type() {
DataType::I8 => MorphTargetWeights::I8(Iter::new(output, slice)),
DataType::U8 => MorphTargetWeights::U8(Iter::new(output, slice)),
DataType::I16 => MorphTargetWeights::I16(Iter::new(output, slice)),
DataType::U16 => MorphTargetWeights::U16(Iter::new(output, slice)),
DataType::F32 => MorphTargetWeights::F32(Iter::new(output, slice)),
_ => unreachable!()
}),
}
)
} else {
None
}
}
}