Added color render
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
//! This module contains the FaceVertex struct.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
/// The indices needed for each vertex of a face.
|
||||
pub struct FaceVertex {
|
||||
|
||||
/// The index of the vertex.
|
||||
pub vertex: usize,
|
||||
|
||||
/// The index of the texture coordinate, None if there is no texture coordinate.
|
||||
pub texture_coordinate: Option<usize>,
|
||||
|
||||
/// The index of the normal, None if there is no normal.
|
||||
pub normal: Option<usize>,
|
||||
}
|
||||
|
||||
impl FaceVertex {
|
||||
|
||||
/// Creates a new face vertex from its attributes.
|
||||
pub fn new(vertex: usize, texture_coordinate: Option<usize>, normal: Option<usize>) -> FaceVertex {
|
||||
FaceVertex {
|
||||
vertex: vertex,
|
||||
texture_coordinate: texture_coordinate,
|
||||
normal: normal,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl fmt::Debug for FaceVertex {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
||||
let texture_coordinate = if let Some(tc) = self.texture_coordinate {
|
||||
tc.to_string()
|
||||
} else {
|
||||
"".to_owned()
|
||||
};
|
||||
|
||||
let normal = if let Some(n) = self.normal {
|
||||
n.to_string()
|
||||
} else {
|
||||
"".to_owned()
|
||||
};
|
||||
|
||||
write!(formatter, "{}/{}/{}", self.vertex, texture_coordinate, normal)
|
||||
}
|
||||
}
|
||||
+23
-1
@@ -26,9 +26,10 @@ pub struct Vertex {
|
||||
vertex: [f64; 3],
|
||||
tex_coords: [f64; 2],
|
||||
normal: [f64; 3],
|
||||
face_color: [f64; 3],
|
||||
}
|
||||
|
||||
implement_vertex!(Vertex, vertex, tex_coords, normal);
|
||||
implement_vertex!(Vertex, vertex, tex_coords, normal, face_color);
|
||||
|
||||
/// A part of a 3D model.
|
||||
///
|
||||
@@ -523,10 +524,26 @@ impl Model {
|
||||
[0.0, 0.0, 0.0]
|
||||
};
|
||||
|
||||
let [r, g, b] = if let Some(id) = face.id {
|
||||
let b = (id % 256) as u8;
|
||||
let g = ((id - b as usize) / 256 % 256) as u8;
|
||||
let r = ((id - g as usize * 256 - b as usize) / (256 * 256)) as u8;
|
||||
[r, g, b]
|
||||
} else {
|
||||
[255, 255, 255]
|
||||
};
|
||||
|
||||
let [r, g, b] = [
|
||||
r as f64 / 255.0,
|
||||
g as f64 / 255.0,
|
||||
b as f64 / 255.0,
|
||||
];
|
||||
|
||||
vertex_buffer.push(Vertex {
|
||||
vertex: vertex,
|
||||
tex_coords: tex_coord,
|
||||
normal: normal,
|
||||
face_color: [r, g, b],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -567,4 +584,9 @@ impl Model {
|
||||
pub fn textures_mut(&mut self) -> &mut HashMap<String, Rc<SrgbTexture2d>> {
|
||||
&mut self.textures
|
||||
}
|
||||
|
||||
/// Clears the OpenGL textures.
|
||||
pub fn clear_textures(&mut self) {
|
||||
self.textures = HashMap::new();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user