diff --git a/src/importer/obj.rs b/src/importer/obj.rs index bde87bd..83e95a6 100644 --- a/src/importer/obj.rs +++ b/src/importer/obj.rs @@ -290,7 +290,12 @@ pub fn load_obj(obj_path: &PathBuf, file: std::fs::File) -> Result().unwrap() - 1; + let mut normal = it.next().unwrap().parse::().unwrap(); + if normal < 0 { + normal = normals.len() as i32 + normal; + } else { + normal -= 1; + } vertices.push(Vertex{ position: *temp_vertices.get(vert as usize).unwrap(), normal: *normals.get(normal as usize).unwrap(), @@ -304,8 +309,18 @@ pub fn load_obj(obj_path: &PathBuf, file: std::fs::File) -> Result().unwrap() - 1; - let normal = it.next().unwrap().parse::().unwrap() - 1; + let mut t_coords = it.next().unwrap().parse::().unwrap(); + if t_coords < 0 { + t_coords = tex_coords.len() as i32 + t_coords; + } else { + t_coords -= 1; + } + let mut normal = it.next().unwrap().parse::().unwrap(); + if normal < 0 { + normal = normals.len() as i32 + normal; + } else { + normal -= 1; + } vertices.push(Vertex{ position: *temp_vertices.get(vertex as usize).unwrap(), normal: *normals.get(normal as usize).unwrap(), @@ -319,7 +334,12 @@ pub fn load_obj(obj_path: &PathBuf, file: std::fs::File) -> Result().unwrap() - 1; + let mut t_coords = it.next().unwrap().parse::().unwrap(); + if t_coords < 0 { + t_coords = tex_coords.len() as i32 + t_coords; + } else { + t_coords -= 1; + } vertices.push(Vertex{ position: *temp_vertices.get(vertex as usize).unwrap(), normal: calculated_normal, @@ -339,7 +359,7 @@ pub fn load_obj(obj_path: &PathBuf, file: std::fs::File) -> Result Result { // we don't handle lines or points } + Some(ObjToken::SmoothShading) => { + // idc about this + } _ => { warn!("Unhandled obj token: {}", token) }, } }