Skip to content

Commit

Permalink
Merge pull request #64 from joshlengel/patch-1
Browse files Browse the repository at this point in the history
Fix mtllib file name parsing bug for paths including spaces
  • Loading branch information
Twinklebear authored Mar 27, 2024
2 parents 7ebb579 + fb5645c commit d934e0b
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,25 +1742,23 @@ where
}
}
Some("mtllib") => {
if let Some(mtllib) = words.next() {
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);
// File name can include spaces so we cannot rely on a SplitWhitespace iterator
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") => {
Expand Down

0 comments on commit d934e0b

Please sign in to comment.