diff --git a/Cargo.toml b/Cargo.toml index 553ad82..3de8011 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ gl = "0.14.0" glm = "0.2.3" field-offset = "0.3.4" image = "0.24.5" -tobj = "3.2.4" +tobj = "0.1.6" cgmath = "0.18.0" [dependencies.glfw] version = "*" diff --git a/models/backpack/ao.jpg b/resources/models/backpack/ao.jpg similarity index 100% rename from models/backpack/ao.jpg rename to resources/models/backpack/ao.jpg diff --git a/models/backpack/backpack.mtl b/resources/models/backpack/backpack.mtl similarity index 100% rename from models/backpack/backpack.mtl rename to resources/models/backpack/backpack.mtl diff --git a/models/backpack/diffuse.jpg b/resources/models/backpack/diffuse.jpg similarity index 100% rename from models/backpack/diffuse.jpg rename to resources/models/backpack/diffuse.jpg diff --git a/models/backpack/backpack.obj b/resources/models/backpack/model.obj similarity index 100% rename from models/backpack/backpack.obj rename to resources/models/backpack/model.obj diff --git a/models/backpack/normal.png b/resources/models/backpack/normal.png similarity index 100% rename from models/backpack/normal.png rename to resources/models/backpack/normal.png diff --git a/models/backpack/roughness.jpg b/resources/models/backpack/roughness.jpg similarity index 100% rename from models/backpack/roughness.jpg rename to resources/models/backpack/roughness.jpg diff --git a/models/backpack/source_attribution.txt b/resources/models/backpack/source_attribution.txt similarity index 100% rename from models/backpack/source_attribution.txt rename to resources/models/backpack/source_attribution.txt diff --git a/models/backpack/specular.jpg b/resources/models/backpack/specular.jpg similarity index 100% rename from models/backpack/specular.jpg rename to resources/models/backpack/specular.jpg diff --git a/src/main.rs b/src/main.rs index c4cb83a..d566b22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,8 +44,9 @@ fn main() { // put biggie thingies here let model_Shader = shader::shader::new("model"); - let ourModel = Model::new("backpack/backpack.obj"); + let ourModel = Model::new("resources/models/backpack"); + println!("entering main loop, time since init: {} seconds", glfw.get_time()); // NOTE window loop while !window.should_close() { glfw.poll_events(); @@ -57,7 +58,7 @@ fn main() { // view/projection transformations - //let projection:; + //; unsafe { diff --git a/src/model.rs b/src/model.rs index bf42068..f6d2b78 100644 --- a/src/model.rs +++ b/src/model.rs @@ -29,11 +29,14 @@ impl Model { } fn loadModel(&mut self, path: &str) { + + let tempPath: String = format!("{}/model.obj", path); let path = Path::new(path); + let modelPath = Path::new(&tempPath); self.directory = path.parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().into(); - let obj = tobj::load_obj(path, &tobj::LoadOptions::default()); + let obj = tobj::load_obj(modelPath); let (models, materials) = obj.unwrap(); for model in models { @@ -47,8 +50,8 @@ impl Model { let (p, n, t) = (&mesh.positions, &mesh.normals, &mesh.texcoords); for i in 0..num_vertices { vertices.push(mesh::Vertex { - Position: vec3(p[i*3], p[i*3+1], p[i*3+2]), - Normal: vec3(n[i*3], n[i*3+1], n[i*3+2]), + Position: vec3(p[i*3], p[i*3+1], p[i*3+2]), + Normal: vec3(n[i*3], n[i*3+1], n[i*3+2]), TexCoords: vec2(t[i*2], t[i*2+1]), ..mesh::Vertex::default() }) @@ -57,24 +60,25 @@ impl Model { // process let mut textures = Vec::new(); if let Some(material_id) = mesh.material_id { - let material = &materials.as_ref().unwrap()[material_id]; + let material = &materials[material_id]; // 1. diffuse map // if !material.diffuse_texture.is_empty() { - let texture = self.loadMaterialTexture(&material.diffuse_texture, "texture_diffuse"); + let texture = self.loadMaterialTexture( &path.join(&material.diffuse_texture).display().to_string(), "texture_diffuse"); textures.push(texture); } // 2.specular map if !material.specular_texture.is_empty() { - let texture = self.loadMaterialTexture(&material.specular_texture, "texture_specular"); + let texture = self.loadMaterialTexture(&path.join(&material.specular_texture).display().to_string(), "texture_specular"); textures.push(texture); } // 3.normal // if !material.normal_texture.is_empty() { - let texture = self.loadMaterialTexture(&material.normal_texture, "texture_normal"); + let texture = self.loadMaterialTexture(&path.join(&material.normal_texture).display().to_string(), "texture_normal"); textures.push(texture); + } } self.meshes.push(mesh::Mesh::new(vertices,indices, textures)); @@ -107,7 +111,7 @@ impl Model { fn TextureFromFile(path: &str) -> u32 { - let filename = format!("resources/models/{}", path); + let filename = path; let mut textureID = 0; @@ -122,7 +126,8 @@ fn TextureFromFile(path: &str) -> u32 gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32); gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32); - let img = image::open(Path::new(&filename)).expect("Failed to load Texture"); + let img = image::open(Path::new(&filename)) + .expect("failed to load texture"); img.flipv(); let format = match img { image::DynamicImage::ImageLuma8(_) => gl::RED, diff --git a/src/model/mesh.rs b/src/model/mesh.rs index 89002b3..432a9a3 100644 --- a/src/model/mesh.rs +++ b/src/model/mesh.rs @@ -6,6 +6,7 @@ use field_offset::offset_of; use cgmath::{Vector3, Vector2}; use cgmath::prelude::*; +#[repr(C)] pub struct Vertex { pub Position: Vector3, pub Normal: Vector3,