Skip to content

Commit

Permalink
Fixed material writing process.
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshi7190 committed Aug 7, 2024
1 parent 2d5cba4 commit d0e470d
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions nusamai/src/sink/obj/obj_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn write_obj<W: Write>(

let mut global_vertex_offset = 0;

let mut texture_cache: HashMap<String, Vec<u8>> = HashMap::new();
let mut material_written: HashSet<String> = HashSet::new();

Check warning on line 24 in nusamai/src/sink/obj/obj_writer.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/obj_writer.rs#L22-L24

Added lines #L22 - L24 were not covered by tests

for (feature_id, feature_data) in &feature_vertex_data {

Check warning on line 26 in nusamai/src/sink/obj/obj_writer.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/obj_writer.rs#L26

Added line #L26 was not covered by tests
Expand Down Expand Up @@ -72,22 +71,18 @@ pub fn write_obj<W: Write>(
let image_file_name =
format!("Feature_{}_Material_{}.jpg", feature_id, material_id);

// Load only if the texture is not in the cache.
if !texture_cache.contains_key(&image_file_name) {
let mat_key = format!("{}_{}", feature_id, material_id);

// Write to MTL file only if material information has not yet been written
if !material_written.contains(&mat_key) {
let content = load_image(feedback, &path)?;

Check warning on line 78 in nusamai/src/sink/obj/obj_writer.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/obj_writer.rs#L69-L78

Added lines #L69 - L78 were not covered by tests
texture_cache.insert(image_file_name.clone(), content);

let textures_dir = file_path.join("textures");
std::fs::create_dir_all(&textures_dir)?;

Check warning on line 81 in nusamai/src/sink/obj/obj_writer.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/obj_writer.rs#L80-L81

Added lines #L80 - L81 were not covered by tests

let image_path = textures_dir.join(&image_file_name);
std::fs::write(&image_path, texture_cache.get(&image_file_name).unwrap())?;
}
std::fs::write(&image_path, content)?;

Check warning on line 84 in nusamai/src/sink/obj/obj_writer.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/obj_writer.rs#L83-L84

Added lines #L83 - L84 were not covered by tests

// Write to MTL file only if material information has not yet been written
let mat_key = format!("{}_{}", feature_id, material_id);

if !material_written.contains(&mat_key) {
writeln!(mtl_writer, "newmtl Material_{}", mat_key)?;
writeln!(mtl_writer, "map_Kd .\\textures\\{}", image_file_name)?;
material_written.insert(mat_key);
Expand Down

0 comments on commit d0e470d

Please sign in to comment.