1pub mod colors;
3
4pub mod indices;
6
7pub mod joints;
9
10pub mod tex_coords;
12
13pub mod weights;
15
16use crate::mesh;
17
18use crate::accessor::Iter;
19use crate::Buffer;
20
21pub type ReadPositions<'a> = Iter<'a, [f32; 3]>;
23
24pub type ReadNormals<'a> = Iter<'a, [f32; 3]>;
26
27pub type ReadTangents<'a> = Iter<'a, [f32; 4]>;
30
31pub type ReadPositionDisplacements<'a> = Iter<'a, [f32; 3]>;
33
34pub type ReadNormalDisplacements<'a> = Iter<'a, [f32; 3]>;
36
37pub type ReadTangentDisplacements<'a> = Iter<'a, [f32; 3]>;
39
40#[derive(Clone, Debug)]
42pub enum ReadColors<'a> {
43 RgbU8(Iter<'a, [u8; 3]>),
45 RgbU16(Iter<'a, [u16; 3]>),
47 RgbF32(Iter<'a, [f32; 3]>),
49 RgbaU8(Iter<'a, [u8; 4]>),
51 RgbaU16(Iter<'a, [u16; 4]>),
53 RgbaF32(Iter<'a, [f32; 4]>),
55}
56
57#[derive(Clone, Debug)]
59pub enum ReadIndices<'a> {
60 U8(Iter<'a, u8>),
62 U16(Iter<'a, u16>),
64 U32(Iter<'a, u32>),
66}
67
68#[derive(Clone, Debug)]
70pub enum ReadJoints<'a> {
71 U8(Iter<'a, [u8; 4]>),
75 U16(Iter<'a, [u16; 4]>),
79}
80
81#[derive(Clone, Debug)]
83pub enum ReadTexCoords<'a> {
84 U8(Iter<'a, [u8; 2]>),
86 U16(Iter<'a, [u16; 2]>),
88 F32(Iter<'a, [f32; 2]>),
90}
91
92#[derive(Clone, Debug)]
94pub enum ReadWeights<'a> {
95 U8(Iter<'a, [u8; 4]>),
97 U16(Iter<'a, [u16; 4]>),
99 F32(Iter<'a, [f32; 4]>),
101}
102
103#[derive(Clone, Debug)]
105pub struct ReadMorphTargets<'a, 's, F>
106where
107 F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
108{
109 pub(crate) index: usize,
110 pub(crate) reader: mesh::Reader<'a, 's, F>,
111}
112
113impl<'a, 's, F> ExactSizeIterator for ReadMorphTargets<'a, 's, F> where
114 F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>
115{
116}
117
118impl<'a, 's, F> Iterator for ReadMorphTargets<'a, 's, F>
119where
120 F: Clone + Fn(Buffer<'a>) -> Option<&'s [u8]>,
121{
122 type Item = (
123 Option<ReadPositionDisplacements<'s>>,
124 Option<ReadNormalDisplacements<'s>>,
125 Option<ReadTangentDisplacements<'s>>,
126 );
127 fn next(&mut self) -> Option<Self::Item> {
128 self.index += 1;
129 self.reader
130 .primitive
131 .morph_targets()
132 .nth(self.index - 1)
133 .map(|morph_target| {
134 let positions = morph_target
135 .positions()
136 .and_then(|accessor| Iter::new(accessor, self.reader.get_buffer_data.clone()));
137 let normals = morph_target
138 .normals()
139 .and_then(|accessor| Iter::new(accessor, self.reader.get_buffer_data.clone()));
140 let tangents = morph_target
141 .tangents()
142 .and_then(|accessor| Iter::new(accessor, self.reader.get_buffer_data.clone()));
143 (positions, normals, tangents)
144 })
145 }
146
147 fn size_hint(&self) -> (usize, Option<usize>) {
148 self.reader.primitive.morph_targets().size_hint()
149 }
150}
151
152impl<'a> ReadColors<'a> {
153 pub fn into_rgb_u8(self) -> self::colors::CastingIter<'a, self::colors::RgbU8> {
156 self::colors::CastingIter::new(self)
157 }
158
159 pub fn into_rgb_u16(self) -> self::colors::CastingIter<'a, self::colors::RgbU16> {
162 self::colors::CastingIter::new(self)
163 }
164
165 pub fn into_rgb_f32(self) -> self::colors::CastingIter<'a, self::colors::RgbF32> {
168 self::colors::CastingIter::new(self)
169 }
170
171 pub fn into_rgba_u8(self) -> self::colors::CastingIter<'a, self::colors::RgbaU8> {
174 self::colors::CastingIter::new(self)
175 }
176
177 pub fn into_rgba_u16(self) -> self::colors::CastingIter<'a, self::colors::RgbaU16> {
180 self::colors::CastingIter::new(self)
181 }
182
183 pub fn into_rgba_f32(self) -> self::colors::CastingIter<'a, self::colors::RgbaF32> {
186 self::colors::CastingIter::new(self)
187 }
188}
189
190impl<'a> ReadIndices<'a> {
191 pub fn into_u32(self) -> self::indices::CastingIter<'a, self::indices::U32> {
193 self::indices::CastingIter::new(self)
194 }
195}
196
197impl<'a> ReadJoints<'a> {
198 pub fn into_u16(self) -> self::joints::CastingIter<'a, self::joints::U16> {
200 self::joints::CastingIter::new(self)
201 }
202}
203
204impl<'a> ReadTexCoords<'a> {
205 pub fn into_u8(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::U8> {
208 self::tex_coords::CastingIter::new(self)
209 }
210
211 pub fn into_u16(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::U16> {
214 self::tex_coords::CastingIter::new(self)
215 }
216
217 pub fn into_f32(self) -> self::tex_coords::CastingIter<'a, self::tex_coords::F32> {
220 self::tex_coords::CastingIter::new(self)
221 }
222}
223
224impl<'a> ReadWeights<'a> {
225 pub fn into_u8(self) -> self::weights::CastingIter<'a, self::weights::U8> {
228 self::weights::CastingIter::new(self)
229 }
230
231 pub fn into_u16(self) -> self::weights::CastingIter<'a, self::weights::U16> {
234 self::weights::CastingIter::new(self)
235 }
236
237 pub fn into_f32(self) -> self::weights::CastingIter<'a, self::weights::F32> {
240 self::weights::CastingIter::new(self)
241 }
242}