clone_without_buffers

This commit is contained in:
Thomas Forgione 2019-09-17 13:27:24 +02:00
parent fdaf28ebf2
commit 13dedc1b27
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 27 additions and 1 deletions

View File

@ -4,7 +4,6 @@
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]

View File

@ -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

View File

@ -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 {