it runs now
|
@ -10,7 +10,7 @@ gl = "0.14.0"
|
||||||
glm = "0.2.3"
|
glm = "0.2.3"
|
||||||
field-offset = "0.3.4"
|
field-offset = "0.3.4"
|
||||||
image = "0.24.5"
|
image = "0.24.5"
|
||||||
tobj = "3.2.4"
|
tobj = "0.1.6"
|
||||||
cgmath = "0.18.0"
|
cgmath = "0.18.0"
|
||||||
[dependencies.glfw]
|
[dependencies.glfw]
|
||||||
version = "*"
|
version = "*"
|
||||||
|
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 5.8 MiB After Width: | Height: | Size: 5.8 MiB |
Before Width: | Height: | Size: 14 MiB After Width: | Height: | Size: 14 MiB |
Before Width: | Height: | Size: 4.2 MiB After Width: | Height: | Size: 4.2 MiB |
Before Width: | Height: | Size: 6.4 MiB After Width: | Height: | Size: 6.4 MiB |
|
@ -44,8 +44,9 @@ fn main() {
|
||||||
|
|
||||||
// put biggie thingies here
|
// put biggie thingies here
|
||||||
let model_Shader = shader::shader::new("model");
|
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
|
// NOTE window loop
|
||||||
while !window.should_close() {
|
while !window.should_close() {
|
||||||
glfw.poll_events();
|
glfw.poll_events();
|
||||||
|
@ -57,7 +58,7 @@ fn main() {
|
||||||
|
|
||||||
|
|
||||||
// view/projection transformations
|
// view/projection transformations
|
||||||
//let projection:;
|
//;
|
||||||
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
19
src/model.rs
|
@ -29,11 +29,14 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn loadModel(&mut self, path: &str) {
|
fn loadModel(&mut self, path: &str) {
|
||||||
|
|
||||||
|
let tempPath: String = format!("{}/model.obj", path);
|
||||||
let path = Path::new(path);
|
let path = Path::new(path);
|
||||||
|
let modelPath = Path::new(&tempPath);
|
||||||
|
|
||||||
|
|
||||||
self.directory = path.parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().into();
|
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();
|
let (models, materials) = obj.unwrap();
|
||||||
for model in models {
|
for model in models {
|
||||||
|
@ -57,24 +60,25 @@ impl Model {
|
||||||
// process
|
// process
|
||||||
let mut textures = Vec::new();
|
let mut textures = Vec::new();
|
||||||
if let Some(material_id) = mesh.material_id {
|
if let Some(material_id) = mesh.material_id {
|
||||||
let material = &materials.as_ref().unwrap()[material_id];
|
let material = &materials[material_id];
|
||||||
// 1. diffuse map
|
// 1. diffuse map
|
||||||
//
|
//
|
||||||
if !material.diffuse_texture.is_empty() {
|
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);
|
textures.push(texture);
|
||||||
}
|
}
|
||||||
// 2.specular map
|
// 2.specular map
|
||||||
if !material.specular_texture.is_empty() {
|
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);
|
textures.push(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.normal
|
// 3.normal
|
||||||
//
|
//
|
||||||
if !material.normal_texture.is_empty() {
|
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);
|
textures.push(texture);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.meshes.push(mesh::Mesh::new(vertices,indices, textures));
|
self.meshes.push(mesh::Mesh::new(vertices,indices, textures));
|
||||||
|
@ -107,7 +111,7 @@ impl Model {
|
||||||
|
|
||||||
fn TextureFromFile(path: &str) -> u32
|
fn TextureFromFile(path: &str) -> u32
|
||||||
{
|
{
|
||||||
let filename = format!("resources/models/{}", path);
|
let filename = path;
|
||||||
|
|
||||||
let mut textureID = 0;
|
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_MIN_FILTER, gl::LINEAR as i32);
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_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();
|
img.flipv();
|
||||||
let format = match img {
|
let format = match img {
|
||||||
image::DynamicImage::ImageLuma8(_) => gl::RED,
|
image::DynamicImage::ImageLuma8(_) => gl::RED,
|
||||||
|
|
|
@ -6,6 +6,7 @@ use field_offset::offset_of;
|
||||||
use cgmath::{Vector3, Vector2};
|
use cgmath::{Vector3, Vector2};
|
||||||
use cgmath::prelude::*;
|
use cgmath::prelude::*;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
pub Position: Vector3<f32>,
|
pub Position: Vector3<f32>,
|
||||||
pub Normal: Vector3<f32>,
|
pub Normal: Vector3<f32>,
|
||||||
|
|