diff --git a/src/lib.rs b/src/lib.rs index 41f6454..d0f768f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ extern crate serde; -#[macro_use] extern crate serde_derive; #[macro_use] diff --git a/src/model/mod.rs b/src/model/mod.rs index b561f30..15aafa4 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -82,6 +82,16 @@ impl Part { &self.faces } + /// Clones a part but without the vertex buffers. + pub fn clone_without_buffer(&self) -> Part { + Part { + material_name: self.material_name.clone(), + faces: self.faces.clone(), + vertex_buffer: None, + needs_update: true, + } + } + } @@ -139,6 +149,20 @@ impl Model { } } + /// Clones the model but without the vertex buffers. + pub fn clone_without_buffers(&self) -> Model { + Model { + vertices: self.vertices.clone(), + texture_coordinates: self.texture_coordinates.clone(), + normals: self.normals.clone(), + faces: self.faces.clone(), + materials: self.materials.clone(), + textures: self.textures.clone(), + parts: self.parts.iter().map(Part::clone_without_buffer).collect(), + current_part_index: self.current_part_index.clone(), + } + } + /// Copies the materials and textures from the other model into self. pub fn merge_material_and_textures(&mut self, other: &Model) { // Merge the materials diff --git a/src/renderer.rs b/src/renderer.rs index 66f13c0..3e3a5ab 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -194,6 +194,9 @@ impl Renderer { if let &Some(ref buffer) = part.vertex_buffer() { let diffuse = if let Some(ref name) = part.material_name { + if let None = model.materials.get(name) { + panic!("Material {} not found", name); + } let t = model.materials.get(name).unwrap().diffuse; Vector3::new(t[0] as f32, t[1] as f32, t[2] as f32) } else {