Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix material changes within an object being ignored #11

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,24 @@ pub fn load_obj_buf<B, ML>(reader: &mut B, material_loader: ML) -> LoadResult
}
Some("usemtl") => {
if let Some(mat_name) = words.next() {
match mat_map.get(mat_name) {
Some(m) => mat_id = Some(*m),
None => {
mat_id = None;
println!("Warning: Object {} refers to unfound material: {}",
name,
mat_name);
}
let new_mat = mat_map.get(mat_name).cloned();
// As materials are returned per-model, a new material within an object
// has to emit a new model with the same name but different material
if mat_id != new_mat && !tmp_faces.is_empty() {
models.push(Model::new(export_faces(&tmp_pos,
&tmp_texcoord,
&tmp_normal,
&tmp_faces,
mat_id),
name.clone()));
tmp_faces.clear();
}
if new_mat.is_none() {
println!("Warning: Object {} refers to unfound material: {}",
name,
mat_name);
}
mat_id = new_mat;
} else {
return Err(LoadError::MaterialParseError);
}
Expand Down