use import;
use json;
use root;
use std::{fmt, iter, ops, slice};
use accessor::Accessor;
use animation::Animation;
use buffer::{Buffer, View};
use camera::Camera;
use image::Image;
use material::Material;
use mesh::Mesh;
use scene::{Node, Scene};
use skin::Skin;
use texture::{Sampler, Texture};
pub struct Gltf {
buffer_data: Vec<import::Data>,
image_data: Vec<import::DynamicImage>,
root: root::Root,
}
#[derive(Clone, Debug)]
pub struct Accessors<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::accessor::Accessor>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Animations<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::animation::Animation>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Buffers<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::buffer::Buffer>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Views<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::buffer::View>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Cameras<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::camera::Camera>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Images<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::image::Image>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Materials<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::material::Material>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Meshes<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::mesh::Mesh>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Nodes<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::scene::Node>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Samplers<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::texture::Sampler>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Scenes<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::scene::Scene>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Skins<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::skin::Skin>>,
gltf: &'a Gltf,
}
#[derive(Clone, Debug)]
pub struct Textures<'a> {
iter: iter::Enumerate<slice::Iter<'a, json::texture::Texture>>,
gltf: &'a Gltf,
}
impl Gltf {
pub fn new(
root: root::Root,
buffer_data: Vec<import::Data>,
image_data: Vec<import::DynamicImage>,
) -> Self {
Self {
buffer_data: buffer_data,
image_data: image_data,
root: root,
}
}
pub fn buffer_data(&self, index: usize) -> import::Data {
self.buffer_data[index].clone()
}
pub fn image_data<'a>(&'a self, index: usize) -> &'a import::DynamicImage {
&self.image_data[index]
}
pub fn accessors<'a>(&'a self) -> Accessors<'a> {
Accessors {
iter: self.as_json().accessors.iter().enumerate(),
gltf: self,
}
}
pub fn animations<'a>(&'a self) -> Animations<'a> {
Animations {
iter: self.as_json().animations.iter().enumerate(),
gltf: self,
}
}
pub fn buffers<'a>(&'a self) -> Buffers<'a> {
Buffers {
iter: self.as_json().buffers.iter().enumerate(),
gltf: self,
}
}
pub fn views<'a>(&'a self) -> Views<'a> {
Views {
iter: self.as_json().buffer_views.iter().enumerate(),
gltf: self,
}
}
pub fn cameras<'a>(&'a self) -> Cameras<'a> {
Cameras {
iter: self.as_json().cameras.iter().enumerate(),
gltf: self,
}
}
pub fn images<'a>(&'a self) -> Images<'a> {
Images {
iter: self.as_json().images.iter().enumerate(),
gltf: self,
}
}
pub fn materials<'a>(&'a self) -> Materials<'a> {
Materials {
iter: self.as_json().materials.iter().enumerate(),
gltf: self,
}
}
pub fn meshes<'a>(&'a self) -> Meshes<'a> {
Meshes {
iter: self.as_json().meshes.iter().enumerate(),
gltf: self,
}
}
pub fn nodes<'a>(&'a self) -> Nodes<'a> {
Nodes {
iter: self.as_json().nodes.iter().enumerate(),
gltf: self,
}
}
pub fn samplers<'a>(&'a self) -> Samplers<'a> {
Samplers {
iter: self.as_json().samplers.iter().enumerate(),
gltf: self,
}
}
pub fn scenes<'a>(&'a self) -> Scenes<'a> {
Scenes {
iter: self.as_json().scenes.iter().enumerate(),
gltf: self,
}
}
pub fn skins<'a>(&'a self) -> Skins<'a> {
Skins {
iter: self.as_json().skins.iter().enumerate(),
gltf: self,
}
}
pub fn textures<'a>(&'a self) -> Textures<'a> {
Textures {
iter: self.as_json().textures.iter().enumerate(),
gltf: self,
}
}
}
impl fmt::Debug for Gltf {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.root)
}
}
impl ops::Deref for Gltf {
type Target = root::Root;
fn deref(&self) -> &Self::Target {
&self.root
}
}
impl<'a> Iterator for Accessors<'a> {
type Item = Accessor<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Accessor::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Animations<'a> {
type Item = Animation<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Animation::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Buffers<'a> {
type Item = Buffer<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Buffer::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Views<'a> {
type Item = View<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| View::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Cameras<'a> {
type Item = Camera<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Camera::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Images<'a> {
type Item = Image<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Image::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Materials<'a> {
type Item = Material<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Material::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Meshes<'a> {
type Item = Mesh<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Mesh::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Nodes<'a> {
type Item = Node<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Node::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Samplers<'a> {
type Item = Sampler<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Sampler::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Scenes<'a> {
type Item = Scene<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Scene::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Skins<'a> {
type Item = Skin<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Skin::new(self.gltf, index, json))
}
}
impl<'a> Iterator for Textures<'a> {
type Item = Texture<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(index, json)| Texture::new(self.gltf, index, json))
}
}