Skip to content

Commit

Permalink
wip: trying to load a simple camera to the world from the importer re…
Browse files Browse the repository at this point in the history
…sult.
  • Loading branch information
suspistew committed Feb 23, 2021
1 parent d66fb55 commit 21173b6
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 145 deletions.
36 changes: 0 additions & 36 deletions amethyst_gltf/src/error.rs

This file was deleted.

22 changes: 12 additions & 10 deletions amethyst_gltf/src/importer/gltf_bytes_converter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use gltf::Document;
use atelier_assets::importer::Error;
use gltf::Document;

pub fn convert_bytes(bytes: &Vec<u8>) -> Result<(Document, Vec<gltf::buffer::Data>, Vec<gltf::image::Data>), Error> {
pub fn convert_bytes(
bytes: &Vec<u8>,
) -> Result<(Document, Vec<gltf::buffer::Data>, Vec<gltf::image::Data>), Error> {
log::debug!("Starting Gltf import");
let result = gltf::import_slice(&bytes.as_slice());
let result = gltf::import_slice(&bytes.as_slice());
log::debug!("Import slice has been done with result {:?}", result);
if let Err(err) = result {
log::error!("Import error: {:?}", err);
Expand All @@ -14,20 +16,20 @@ pub fn convert_bytes(bytes: &Vec<u8>) -> Result<(Document, Vec<gltf::buffer::Dat

#[cfg(test)]
mod test {
use super::*;
use super::super::GltfSceneOptions;
use std::fs::File;
use std::io::Read;
use std::{fs::File, io::Read};

use atelier_assets::importer::BoxedImporter;
use type_uuid::TypeUuid;

use super::{super::GltfSceneOptions, *};

#[test]
fn should_import_glb_gltf() {
let mut f = File::open("test/suzanne.glb").expect("suzanne.glb not found");
let mut buffer = Vec::new();
// read the whole file
f.read_to_end(&mut buffer).expect("read_to_end did not work");
f.read_to_end(&mut buffer)
.expect("read_to_end did not work");
let gltf_import = convert_bytes(&buffer);
match gltf_import {
Ok(gltf) => {
Expand All @@ -38,10 +40,10 @@ mod test {
assert_eq!(1, doc.nodes().len());
assert_eq!(1, doc.scenes().len());
assert_eq!(2, doc.textures().len());
},
}
Err(e) => {
panic!("Error during gltf import {:?}", e)
}
}
}
}
}
25 changes: 13 additions & 12 deletions amethyst_gltf/src/importer/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use amethyst_rendy::rendy::mesh::{Position, Normal, TexCoord, Tangent, MeshBuilder, Color};
use mikktspace::{generate_tangents, Geometry};
use std::{iter::repeat, ops::Range};

use amethyst_assets::error::Error;
use amethyst_core::math::{zero, Vector3};
use amethyst_rendy::{
rendy::mesh::{Color, MeshBuilder, Normal, Position, Tangent, TexCoord},
skinning::JointCombined,
};
use gltf::buffer::Data;
use crate::{GltfSceneOptions, error};
use amethyst_assets::error::Error;
use std::ops::Range;
use log::{trace, warn};
use std::iter::repeat;
use amethyst_rendy::skinning::JointCombined;
use mikktspace::{generate_tangents, Geometry};

use crate::GltfSceneOptions;

pub fn load_mesh(
mesh: &gltf::Mesh<'_>,
Expand Down Expand Up @@ -130,14 +133,11 @@ pub fn load_mesh(
let material = primitive.material().index();

primitives.push((builder, material, bounds));

}
trace!("Loaded mesh");
Ok(primitives)
}



fn compute_if<T, F: Fn() -> T>(predicate: bool, func: F) -> Option<T> {
if predicate {
Some(func())
Expand Down Expand Up @@ -255,9 +255,10 @@ fn calculate_tangents(

#[cfg(test)]
mod tests {
use super::{calculate_tangents, Indices};
use amethyst_rendy::rendy::mesh::{Normal, Position, Tangent, TexCoord};

use super::{calculate_tangents, Indices};

const POSITIONS: &[Position] = &[
Position([0.0, 0.0, 0.0]),
Position([0.0, 1.0, 0.0]),
Expand Down Expand Up @@ -319,4 +320,4 @@ mod tests {
]
);
}
}
}
Loading

0 comments on commit 21173b6

Please sign in to comment.