it runs now
|
@ -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 = "*"
|
||||
|
|
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
|
||||
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 {
|
||||
|
|
23
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,
|
||||
|
|
|
@ -6,6 +6,7 @@ use field_offset::offset_of;
|
|||
use cgmath::{Vector3, Vector2};
|
||||
use cgmath::prelude::*;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Vertex {
|
||||
pub Position: Vector3<f32>,
|
||||
pub Normal: Vector3<f32>,
|
||||
|
|