Textures are now shared between materials

This commit is contained in:
Thomas Forgione
2018-04-18 14:19:16 +02:00
parent fdcc580d14
commit 0b6d39541f
2 changed files with 15 additions and 6 deletions
+13
View File
@@ -136,10 +136,12 @@ impl Model {
let normal_offset = self.normals.len();
let face_offset = self.faces.len();
// Merge the elements
self.vertices.append(&mut other.vertices);
self.texture_coordinates.append(&mut other.texture_coordinates);
self.normals.append(&mut other.normals);
// Merge the parts and faces
for part in &mut other.parts {
let mut new_part = Part::new(part.material_name.clone());
for face in &mut part.faces {
@@ -161,6 +163,7 @@ impl Model {
self.parts.push(new_part);
}
// Merge the materials
for (name, material) in other.materials {
let entry = self.materials.entry(name);
if let Entry::Occupied(_) = entry {
@@ -169,6 +172,16 @@ impl Model {
entry.or_insert(material);
}
}
// Merge the textures
for (name, texture) in other.textures {
let entry = self.textures.entry(name);
if let Entry::Occupied(_) = entry {
// return Error;
} else {
entry.or_insert(texture);
}
}
}
/// Creates a model from a file.