1use std::{iter, slice};
2
3use crate::accessor::Accessor;
4use crate::animation::Animation;
5use crate::buffer::{Buffer, View};
6use crate::camera::Camera;
7use crate::image::Image;
8use crate::material::Material;
9use crate::mesh::Mesh;
10use crate::scene::{Node, Scene};
11use crate::skin::Skin;
12use crate::texture::{Sampler, Texture};
13use crate::Document;
14
15#[derive(Clone, Debug)]
17pub struct ExtensionsUsed<'a>(pub(crate) slice::Iter<'a, String>);
18
19#[derive(Clone, Debug)]
21pub struct ExtensionsRequired<'a>(pub(crate) slice::Iter<'a, String>);
22
23#[derive(Clone, Debug)]
25pub struct Accessors<'a> {
26 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::accessor::Accessor>>,
28
29 pub(crate) document: &'a Document,
31}
32
33#[derive(Clone, Debug)]
35pub struct Animations<'a> {
36 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::animation::Animation>>,
38
39 pub(crate) document: &'a Document,
41}
42
43#[derive(Clone, Debug)]
45pub struct Buffers<'a> {
46 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::buffer::Buffer>>,
48
49 pub(crate) document: &'a Document,
51}
52
53#[derive(Clone, Debug)]
55pub struct Views<'a> {
56 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::buffer::View>>,
58
59 pub(crate) document: &'a Document,
61}
62
63#[derive(Clone, Debug)]
65pub struct Cameras<'a> {
66 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::camera::Camera>>,
68
69 pub(crate) document: &'a Document,
71}
72
73#[derive(Clone, Debug)]
75pub struct Images<'a> {
76 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::image::Image>>,
78
79 pub(crate) document: &'a Document,
81}
82
83#[cfg(feature = "KHR_lights_punctual")]
85#[derive(Clone, Debug)]
86pub struct Lights<'a> {
87 pub(crate) iter:
89 iter::Enumerate<slice::Iter<'a, json::extensions::scene::khr_lights_punctual::Light>>,
90
91 pub(crate) document: &'a Document,
93}
94
95#[cfg(feature = "KHR_materials_variants")]
97#[derive(Clone, Debug)]
98pub struct Variants<'a> {
99 pub(crate) iter:
101 iter::Enumerate<slice::Iter<'a, json::extensions::scene::khr_materials_variants::Variant>>,
102
103 pub(crate) document: &'a Document,
105}
106
107#[derive(Clone, Debug)]
109pub struct Materials<'a> {
110 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::material::Material>>,
112
113 pub(crate) document: &'a Document,
115}
116
117#[derive(Clone, Debug)]
119pub struct Meshes<'a> {
120 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::mesh::Mesh>>,
122
123 pub(crate) document: &'a Document,
125}
126
127#[derive(Clone, Debug)]
129pub struct Nodes<'a> {
130 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::scene::Node>>,
132
133 pub(crate) document: &'a Document,
135}
136
137#[derive(Clone, Debug)]
139pub struct Samplers<'a> {
140 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::texture::Sampler>>,
142
143 pub(crate) document: &'a Document,
145}
146
147#[derive(Clone, Debug)]
149pub struct Scenes<'a> {
150 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::scene::Scene>>,
152
153 pub(crate) document: &'a Document,
155}
156
157#[derive(Clone, Debug)]
159pub struct Skins<'a> {
160 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::skin::Skin>>,
162
163 pub(crate) document: &'a Document,
165}
166
167#[derive(Clone, Debug)]
169pub struct Textures<'a> {
170 pub(crate) iter: iter::Enumerate<slice::Iter<'a, json::texture::Texture>>,
172
173 pub(crate) document: &'a Document,
175}
176
177impl<'a> ExactSizeIterator for Accessors<'a> {}
178impl<'a> Iterator for Accessors<'a> {
179 type Item = Accessor<'a>;
180 fn next(&mut self) -> Option<Self::Item> {
181 self.iter
182 .next()
183 .map(|(index, json)| Accessor::new(self.document, index, json))
184 }
185 fn size_hint(&self) -> (usize, Option<usize>) {
186 self.iter.size_hint()
187 }
188 fn count(self) -> usize {
189 self.iter.count()
190 }
191 fn last(self) -> Option<Self::Item> {
192 let document = self.document;
193 self.iter
194 .last()
195 .map(|(index, json)| Accessor::new(document, index, json))
196 }
197 fn nth(&mut self, n: usize) -> Option<Self::Item> {
198 self.iter
199 .nth(n)
200 .map(|(index, json)| Accessor::new(self.document, index, json))
201 }
202}
203
204impl<'a> ExactSizeIterator for Animations<'a> {}
205impl<'a> Iterator for Animations<'a> {
206 type Item = Animation<'a>;
207 fn next(&mut self) -> Option<Self::Item> {
208 self.iter
209 .next()
210 .map(|(index, json)| Animation::new(self.document, index, json))
211 }
212 fn size_hint(&self) -> (usize, Option<usize>) {
213 self.iter.size_hint()
214 }
215 fn count(self) -> usize {
216 self.iter.count()
217 }
218 fn last(self) -> Option<Self::Item> {
219 let document = self.document;
220 self.iter
221 .last()
222 .map(|(index, json)| Animation::new(document, index, json))
223 }
224 fn nth(&mut self, n: usize) -> Option<Self::Item> {
225 self.iter
226 .nth(n)
227 .map(|(index, json)| Animation::new(self.document, index, json))
228 }
229}
230
231impl<'a> ExactSizeIterator for Buffers<'a> {}
232impl<'a> Iterator for Buffers<'a> {
233 type Item = Buffer<'a>;
234 fn next(&mut self) -> Option<Self::Item> {
235 self.iter
236 .next()
237 .map(|(index, json)| Buffer::new(self.document, index, json))
238 }
239 fn size_hint(&self) -> (usize, Option<usize>) {
240 self.iter.size_hint()
241 }
242 fn count(self) -> usize {
243 self.iter.count()
244 }
245 fn last(self) -> Option<Self::Item> {
246 let document = self.document;
247 self.iter
248 .last()
249 .map(|(index, json)| Buffer::new(document, index, json))
250 }
251 fn nth(&mut self, n: usize) -> Option<Self::Item> {
252 self.iter
253 .nth(n)
254 .map(|(index, json)| Buffer::new(self.document, index, json))
255 }
256}
257
258impl<'a> ExactSizeIterator for ExtensionsUsed<'a> {}
259impl<'a> Iterator for ExtensionsUsed<'a> {
260 type Item = &'a str;
261 fn next(&mut self) -> Option<Self::Item> {
262 self.0.next().map(String::as_str)
263 }
264 fn size_hint(&self) -> (usize, Option<usize>) {
265 self.0.size_hint()
266 }
267 fn count(self) -> usize {
268 self.0.count()
269 }
270 fn last(self) -> Option<Self::Item> {
271 self.0.last().map(String::as_str)
272 }
273 fn nth(&mut self, n: usize) -> Option<Self::Item> {
274 self.0.nth(n).map(String::as_str)
275 }
276}
277
278impl<'a> ExactSizeIterator for ExtensionsRequired<'a> {}
279impl<'a> Iterator for ExtensionsRequired<'a> {
280 type Item = &'a str;
281 fn next(&mut self) -> Option<Self::Item> {
282 self.0.next().map(String::as_str)
283 }
284 fn size_hint(&self) -> (usize, Option<usize>) {
285 self.0.size_hint()
286 }
287 fn count(self) -> usize {
288 self.0.count()
289 }
290 fn last(self) -> Option<Self::Item> {
291 self.0.last().map(String::as_str)
292 }
293 fn nth(&mut self, n: usize) -> Option<Self::Item> {
294 self.0.nth(n).map(String::as_str)
295 }
296}
297
298impl<'a> ExactSizeIterator for Views<'a> {}
299impl<'a> Iterator for Views<'a> {
300 type Item = View<'a>;
301 fn next(&mut self) -> Option<Self::Item> {
302 self.iter
303 .next()
304 .map(|(index, json)| View::new(self.document, index, json))
305 }
306 fn size_hint(&self) -> (usize, Option<usize>) {
307 self.iter.size_hint()
308 }
309 fn count(self) -> usize {
310 self.iter.count()
311 }
312 fn last(self) -> Option<Self::Item> {
313 let document = self.document;
314 self.iter
315 .last()
316 .map(|(index, json)| View::new(document, index, json))
317 }
318 fn nth(&mut self, n: usize) -> Option<Self::Item> {
319 self.iter
320 .nth(n)
321 .map(|(index, json)| View::new(self.document, index, json))
322 }
323}
324
325impl<'a> ExactSizeIterator for Cameras<'a> {}
326impl<'a> Iterator for Cameras<'a> {
327 type Item = Camera<'a>;
328 fn next(&mut self) -> Option<Self::Item> {
329 self.iter
330 .next()
331 .map(|(index, json)| Camera::new(self.document, index, json))
332 }
333 fn size_hint(&self) -> (usize, Option<usize>) {
334 self.iter.size_hint()
335 }
336 fn count(self) -> usize {
337 self.iter.count()
338 }
339 fn last(self) -> Option<Self::Item> {
340 let document = self.document;
341 self.iter
342 .last()
343 .map(|(index, json)| Camera::new(document, index, json))
344 }
345 fn nth(&mut self, n: usize) -> Option<Self::Item> {
346 self.iter
347 .nth(n)
348 .map(|(index, json)| Camera::new(self.document, index, json))
349 }
350}
351
352impl<'a> ExactSizeIterator for Images<'a> {}
353impl<'a> Iterator for Images<'a> {
354 type Item = Image<'a>;
355 fn next(&mut self) -> Option<Self::Item> {
356 self.iter
357 .next()
358 .map(|(index, json)| Image::new(self.document, index, json))
359 }
360 fn size_hint(&self) -> (usize, Option<usize>) {
361 self.iter.size_hint()
362 }
363 fn count(self) -> usize {
364 self.iter.count()
365 }
366 fn last(self) -> Option<Self::Item> {
367 let document = self.document;
368 self.iter
369 .last()
370 .map(|(index, json)| Image::new(document, index, json))
371 }
372 fn nth(&mut self, n: usize) -> Option<Self::Item> {
373 self.iter
374 .nth(n)
375 .map(|(index, json)| Image::new(self.document, index, json))
376 }
377}
378
379#[cfg(feature = "KHR_lights_punctual")]
380impl<'a> ExactSizeIterator for Lights<'a> {}
381
382#[cfg(feature = "KHR_lights_punctual")]
383impl<'a> Iterator for Lights<'a> {
384 type Item = crate::khr_lights_punctual::Light<'a>;
385 fn next(&mut self) -> Option<Self::Item> {
386 self.iter
387 .next()
388 .map(|(index, json)| crate::khr_lights_punctual::Light::new(self.document, index, json))
389 }
390 fn size_hint(&self) -> (usize, Option<usize>) {
391 self.iter.size_hint()
392 }
393 fn count(self) -> usize {
394 self.iter.count()
395 }
396 fn last(self) -> Option<Self::Item> {
397 let document = self.document;
398 self.iter
399 .last()
400 .map(|(index, json)| crate::khr_lights_punctual::Light::new(document, index, json))
401 }
402 fn nth(&mut self, n: usize) -> Option<Self::Item> {
403 self.iter
404 .nth(n)
405 .map(|(index, json)| crate::khr_lights_punctual::Light::new(self.document, index, json))
406 }
407}
408
409#[cfg(feature = "KHR_materials_variants")]
410impl<'a> ExactSizeIterator for Variants<'a> {}
411
412#[cfg(feature = "KHR_materials_variants")]
413impl<'a> Iterator for Variants<'a> {
414 type Item = crate::khr_materials_variants::Variant<'a>;
415 fn next(&mut self) -> Option<Self::Item> {
416 self.iter.next().map(|(index, json)| {
417 crate::khr_materials_variants::Variant::new(self.document, index, json)
418 })
419 }
420 fn size_hint(&self) -> (usize, Option<usize>) {
421 self.iter.size_hint()
422 }
423 fn count(self) -> usize {
424 self.iter.count()
425 }
426 fn last(self) -> Option<Self::Item> {
427 let document = self.document;
428 self.iter
429 .last()
430 .map(|(index, json)| crate::khr_materials_variants::Variant::new(document, index, json))
431 }
432 fn nth(&mut self, n: usize) -> Option<Self::Item> {
433 self.iter.nth(n).map(|(index, json)| {
434 crate::khr_materials_variants::Variant::new(self.document, index, json)
435 })
436 }
437}
438
439impl<'a> ExactSizeIterator for Materials<'a> {}
440impl<'a> Iterator for Materials<'a> {
441 type Item = Material<'a>;
442 fn next(&mut self) -> Option<Self::Item> {
443 self.iter
444 .next()
445 .map(|(index, json)| Material::new(self.document, index, json))
446 }
447 fn size_hint(&self) -> (usize, Option<usize>) {
448 self.iter.size_hint()
449 }
450 fn count(self) -> usize {
451 self.iter.count()
452 }
453 fn last(self) -> Option<Self::Item> {
454 let document = self.document;
455 self.iter
456 .last()
457 .map(|(index, json)| Material::new(document, index, json))
458 }
459 fn nth(&mut self, n: usize) -> Option<Self::Item> {
460 self.iter
461 .nth(n)
462 .map(|(index, json)| Material::new(self.document, index, json))
463 }
464}
465
466impl<'a> ExactSizeIterator for Meshes<'a> {}
467impl<'a> Iterator for Meshes<'a> {
468 type Item = Mesh<'a>;
469 fn next(&mut self) -> Option<Self::Item> {
470 self.iter
471 .next()
472 .map(|(index, json)| Mesh::new(self.document, index, json))
473 }
474 fn size_hint(&self) -> (usize, Option<usize>) {
475 self.iter.size_hint()
476 }
477 fn count(self) -> usize {
478 self.iter.count()
479 }
480 fn last(self) -> Option<Self::Item> {
481 let document = self.document;
482 self.iter
483 .last()
484 .map(|(index, json)| Mesh::new(document, index, json))
485 }
486 fn nth(&mut self, n: usize) -> Option<Self::Item> {
487 self.iter
488 .nth(n)
489 .map(|(index, json)| Mesh::new(self.document, index, json))
490 }
491}
492
493impl<'a> ExactSizeIterator for Nodes<'a> {}
494impl<'a> Iterator for Nodes<'a> {
495 type Item = Node<'a>;
496 fn next(&mut self) -> Option<Self::Item> {
497 self.iter
498 .next()
499 .map(|(index, json)| Node::new(self.document, index, json))
500 }
501 fn size_hint(&self) -> (usize, Option<usize>) {
502 self.iter.size_hint()
503 }
504 fn count(self) -> usize {
505 self.iter.count()
506 }
507 fn last(self) -> Option<Self::Item> {
508 let document = self.document;
509 self.iter
510 .last()
511 .map(|(index, json)| Node::new(document, index, json))
512 }
513 fn nth(&mut self, n: usize) -> Option<Self::Item> {
514 self.iter
515 .nth(n)
516 .map(|(index, json)| Node::new(self.document, index, json))
517 }
518}
519
520impl<'a> ExactSizeIterator for Samplers<'a> {}
521impl<'a> Iterator for Samplers<'a> {
522 type Item = Sampler<'a>;
523 fn next(&mut self) -> Option<Self::Item> {
524 self.iter
525 .next()
526 .map(|(index, json)| Sampler::new(self.document, index, json))
527 }
528 fn size_hint(&self) -> (usize, Option<usize>) {
529 self.iter.size_hint()
530 }
531 fn count(self) -> usize {
532 self.iter.count()
533 }
534 fn last(self) -> Option<Self::Item> {
535 let document = self.document;
536 self.iter
537 .last()
538 .map(|(index, json)| Sampler::new(document, index, json))
539 }
540 fn nth(&mut self, n: usize) -> Option<Self::Item> {
541 self.iter
542 .nth(n)
543 .map(|(index, json)| Sampler::new(self.document, index, json))
544 }
545}
546
547impl<'a> ExactSizeIterator for Scenes<'a> {}
548impl<'a> Iterator for Scenes<'a> {
549 type Item = Scene<'a>;
550 fn next(&mut self) -> Option<Self::Item> {
551 self.iter
552 .next()
553 .map(|(index, json)| Scene::new(self.document, index, json))
554 }
555 fn size_hint(&self) -> (usize, Option<usize>) {
556 self.iter.size_hint()
557 }
558 fn count(self) -> usize {
559 self.iter.count()
560 }
561 fn last(self) -> Option<Self::Item> {
562 let document = self.document;
563 self.iter
564 .last()
565 .map(|(index, json)| Scene::new(document, index, json))
566 }
567 fn nth(&mut self, n: usize) -> Option<Self::Item> {
568 self.iter
569 .nth(n)
570 .map(|(index, json)| Scene::new(self.document, index, json))
571 }
572}
573
574impl<'a> ExactSizeIterator for Skins<'a> {}
575impl<'a> Iterator for Skins<'a> {
576 type Item = Skin<'a>;
577 fn next(&mut self) -> Option<Self::Item> {
578 self.iter
579 .next()
580 .map(|(index, json)| Skin::new(self.document, index, json))
581 }
582 fn size_hint(&self) -> (usize, Option<usize>) {
583 self.iter.size_hint()
584 }
585 fn count(self) -> usize {
586 self.iter.count()
587 }
588 fn last(self) -> Option<Self::Item> {
589 let document = self.document;
590 self.iter
591 .last()
592 .map(|(index, json)| Skin::new(document, index, json))
593 }
594 fn nth(&mut self, n: usize) -> Option<Self::Item> {
595 self.iter
596 .nth(n)
597 .map(|(index, json)| Skin::new(self.document, index, json))
598 }
599}
600
601impl<'a> ExactSizeIterator for Textures<'a> {}
602impl<'a> Iterator for Textures<'a> {
603 type Item = Texture<'a>;
604 fn next(&mut self) -> Option<Self::Item> {
605 self.iter
606 .next()
607 .map(|(index, json)| Texture::new(self.document, index, json))
608 }
609 fn size_hint(&self) -> (usize, Option<usize>) {
610 self.iter.size_hint()
611 }
612 fn count(self) -> usize {
613 self.iter.count()
614 }
615 fn last(self) -> Option<Self::Item> {
616 let document = self.document;
617 self.iter
618 .last()
619 .map(|(index, json)| Texture::new(document, index, json))
620 }
621 fn nth(&mut self, n: usize) -> Option<Self::Item> {
622 self.iter
623 .nth(n)
624 .map(|(index, json)| Texture::new(self.document, index, json))
625 }
626}