From f5a11b41c9f358ea19a7a7971a504a0967555e15 Mon Sep 17 00:00:00 2001 From: Josh Lengel Date: Wed, 27 Mar 2024 00:32:28 +0100 Subject: [PATCH 1/2] Fix mtllib file name parsing bug for paths including spaces --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b67d876..9786dfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1742,7 +1742,8 @@ where } } Some("mtllib") => { - if let Some(mtllib) = words.next() { + // File name can include spaces so we cannot rely on a SplitWhitespace iterator + if let Some(mtllib) = line.split_once(' ').unwrap_or_default().1.trim() { let mat_file = Path::new(mtllib).to_path_buf(); match material_loader(mat_file.as_path()) { Ok((mut mats, map)) => { From fb5645c76ae73e89197ed2b0957f902e4eaa8704 Mon Sep 17 00:00:00 2001 From: Josh Lengel Date: Wed, 27 Mar 2024 01:45:18 +0100 Subject: [PATCH 2/2] Fixed type error The argument of mtllib is no longer wrapped by Option. The control logic has been adjusted accordingly --- src/lib.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9786dfb..2c6cbf8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1743,25 +1743,22 @@ where } Some("mtllib") => { // File name can include spaces so we cannot rely on a SplitWhitespace iterator - if let Some(mtllib) = line.split_once(' ').unwrap_or_default().1.trim() { - let mat_file = Path::new(mtllib).to_path_buf(); - match material_loader(mat_file.as_path()) { - Ok((mut mats, map)) => { - // Merge the loaded material lib with any currently loaded ones, - // offsetting the indices of the appended - // materials by our current length - let mat_offset = materials.len(); - materials.append(&mut mats); - for m in map { - mat_map.insert(m.0, m.1 + mat_offset); - } - } - Err(e) => { - mtlresult = Err(e); + let mtllib = line.split_once(' ').unwrap_or_default().1.trim(); + let mat_file = Path::new(mtllib).to_path_buf(); + match material_loader(mat_file.as_path()) { + Ok((mut mats, map)) => { + // Merge the loaded material lib with any currently loaded ones, + // offsetting the indices of the appended + // materials by our current length + let mat_offset = materials.len(); + materials.append(&mut mats); + for m in map { + mat_map.insert(m.0, m.1 + mat_offset); } } - } else { - return Err(LoadError::MaterialParseError); + Err(e) => { + mtlresult = Err(e); + } } } Some("usemtl") => {