pub mod colors;
pub mod indices;
pub mod joints;
pub mod tex_coords;
pub mod weights;
use mesh;
use accessor::Iter;
use Buffer;
pub type ReadPositions<'a> = Iter<'a, [f32; 3]>;
pub type ReadNormals<'a> = Iter<'a, [f32; 3]>;
pub type ReadTangents<'a> = Iter<'a, [f32; 4]>;
pub type ReadPositionDisplacements<'a> = Iter<'a, [f32; 3]>;
pub type ReadNormalDisplacements<'a> = Iter<'a, [f32; 3]>;
pub type ReadTangentDisplacements<'a> = Iter<'a, [f32; 3]>;
#[derive(Clone, Debug)]
pub enum ReadColors<'a> {
RgbU8(Iter<'a, [u8; 3]>),
RgbU16(Iter<'a, [u16; 3]>),
RgbF32(Iter<'a, [f32; 3]>),
RgbaU8(Iter<'a, [u8; 4]>),
RgbaU16(Iter<'a, [u16; 4]>),
RgbaF32(Iter<'a, [f32; 4]>),
}
#[derive(Clone, Debug)]
pub enum ReadIndices<'a> {
U8(Iter<'a, u8>),
U16(Iter<'a, u16>),
U32(Iter<'a, u32>),
}
#[derive(Clone, Debug)]
pub enum ReadJoints<'a> {
U8(Iter<'a, [u8; 4]>),
U16(Iter<'a, [u16; 4]>),
}
#[derive(Clone, Debug)]
pub enum ReadTexCoords<'a> {
U8(Iter<'a, [u8; 2]>),
U16(Iter<'a, [u16; 2]>),
F32(Iter<'a, [f32; 2]>),
}
#[derive(Clone, Debug)]
pub enum ReadWeights<'a> {
U8(Iter<'a, [u8; 4]>),
U16(Iter<'a, [u16; 4]>),
F32(Iter<'a, [f32; 4]>),
}
#[derive(Clone, Debug)]
pub struct ReadMorphTargets<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
pub(crate) index: usize,
pub(crate) reader: mesh::Reader<'a, 's, F>,
}
impl<'a, 's, F> ExactSizeIterator for ReadMorphTargets<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{}
impl<'a, 's, F> Iterator for ReadMorphTargets<'a, 's, F>
where
F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
{
type Item = (
Option<ReadPositionDisplacements<'s>>,
Option<ReadNormalDisplacements<'s>>,
Option<ReadTangentDisplacements<'s>>,
);
fn next(&mut self) -> Option<Self::Item> {
self.index += 1;
self.reader.primitive
.morph_targets()
.nth(self.index - 1)
.map(|morph_target| {
let positions = if let Some(accessor) = morph_target.positions() {
let buffer = accessor.view().buffer();
if let Some(slice) = ((self.reader).get_buffer_data)(buffer) {
Some(Iter::new(accessor, slice))
} else {
None
}
} else {
None
};
let normals = if let Some(accessor) = morph_target.normals() {
let buffer = accessor.view().buffer();
if let Some(slice) = ((self.reader).get_buffer_data)(buffer) {
Some(Iter::new(accessor, slice))
} else {
None
}
} else {
None
};
let tangents = if let Some(accessor) = morph_target.tangents() {
let buffer = accessor.view().buffer();
if let Some(slice) = ((self.reader).get_buffer_data)(buffer) {
Some(Iter::new(accessor, slice))
} else {
None
}
} else {
None
};
(positions, normals, tangents)
})
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.reader.primitive.morph_targets().size_hint()
}
}
impl<'a> ReadColors<'a> {
pub fn into_rgb_u8(self) -> self::colors::CastingIter<'a, self::colors::RgbU8> {
self::colors::CastingIter::new(self)
}
pub fn into_rgb_u16(self) -> self::colors::CastingIter<'a, self::colors::RgbU16> {
self::colors::CastingIter::new(self)
}
pub fn into_rgb_f32(self) -> self::colors::CastingIter<'a, self::colors::RgbF32> {
self::colors::CastingIter::new(self)
}
pub fn into_rgba_u8(self) -> self::colors::CastingIter<'a, self::colors::RgbaU8> {
self::colors::CastingIter::new(self)
}
pub fn into_rgba_u16(self) -> self::colors::CastingIter<'a, self::colors::RgbaU16> {
self::colors::CastingIter::new(self)
}
pub fn into_rgba_f32(self) -> self::colors::CastingIter<'a, self::colors::RgbaF32> {
self::colors::CastingIter::new(self)
}
}
impl<'a> ReadIndices<'a> {
pub fn into_u32(self) -> self::indices::CastingIter<'a, self::indices::U32> {
self::indices::CastingIter::new(self)
}
}
impl<'a> ReadJoints<'a> {
pub fn into_u16(self) -> self::joints::CastingIter<'a, self::joints::U16> {
self::joints::CastingIter::new(self)
}
}
impl<'a> ReadTexCoords<'a> {
pub fn into_u8(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::U8> {
self::tex_coords::CastingIter::new(self)
}
pub fn into_u16(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::U16> {
self::tex_coords::CastingIter::new(self)
}
pub fn into_f32(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::F32> {
self::tex_coords::CastingIter::new(self)
}
}
impl<'a> ReadWeights<'a> {
pub fn into_u8(self) -> self::weights::CastingIter<'a, self::weights::U8> {
self::weights::CastingIter::new(self)
}
pub fn into_u16(self) -> self::weights::CastingIter<'a, self::weights::U16> {
self::weights::CastingIter::new(self)
}
pub fn into_f32(self) -> self::weights::CastingIter<'a, self::weights::F32> {
self::weights::CastingIter::new(self)
}
}