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
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
2 changed files with 15 additions and 6 deletions

View File

@ -136,10 +136,12 @@ impl Model {
let normal_offset = self.normals.len(); let normal_offset = self.normals.len();
let face_offset = self.faces.len(); let face_offset = self.faces.len();
// Merge the elements
self.vertices.append(&mut other.vertices); self.vertices.append(&mut other.vertices);
self.texture_coordinates.append(&mut other.texture_coordinates); self.texture_coordinates.append(&mut other.texture_coordinates);
self.normals.append(&mut other.normals); self.normals.append(&mut other.normals);
// Merge the parts and faces
for part in &mut other.parts { for part in &mut other.parts {
let mut new_part = Part::new(part.material_name.clone()); let mut new_part = Part::new(part.material_name.clone());
for face in &mut part.faces { for face in &mut part.faces {
@ -161,6 +163,7 @@ impl Model {
self.parts.push(new_part); self.parts.push(new_part);
} }
// Merge the materials
for (name, material) in other.materials { for (name, material) in other.materials {
let entry = self.materials.entry(name); let entry = self.materials.entry(name);
if let Entry::Occupied(_) = entry { if let Entry::Occupied(_) = entry {
@ -169,6 +172,16 @@ impl Model {
entry.or_insert(material); 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. /// Creates a model from a file.

View File

@ -11,10 +11,7 @@ use clap::{App, Arg};
use glium::Display; use glium::Display;
use glium::glutin; use glium::glutin;
use glium::glutin::{ use glium::glutin::{EventsLoop, WindowBuilder};
EventsLoop,
WindowBuilder,
};
use glium::glutin::Event; use glium::glutin::Event;
use glium::glutin::WindowEvent; use glium::glutin::WindowEvent;
@ -25,8 +22,7 @@ use model_converter::math::bounding_box::BoundingBox3;
use model_converter::math::vector::Vector3; use model_converter::math::vector::Vector3;
use model_converter::parser::parse; use model_converter::parser::parse;
use model_converter::renderer::Renderer; use model_converter::renderer::Renderer;
use model_converter::controls::OrbitControls; use model_converter::controls::{OrbitControls, FirstPersonControls};
use model_converter::controls::FirstPersonControls;
use model_converter::camera::Camera; use model_converter::camera::Camera;
fn as_millis(duration: Duration) -> u64 { fn as_millis(duration: Duration) -> u64 {