Nice
This commit is contained in:
+25
-10
@@ -23,13 +23,14 @@ use renderer::Renderer;
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
/// A raw vertex, with its 3D coordinates, texture coordinates and normals.
|
||||
pub struct Vertex {
|
||||
vertex: [f64; 3],
|
||||
tex_coords: [f64; 2],
|
||||
normal: [f64; 3],
|
||||
face_color: [f64; 3],
|
||||
vertex: [f64; 3],
|
||||
tex_coords: [f64; 2],
|
||||
normal: [f64; 3],
|
||||
barycentric: [f64; 3],
|
||||
face_color: [f64; 3],
|
||||
}
|
||||
|
||||
implement_vertex!(Vertex, vertex, tex_coords, normal, face_color);
|
||||
implement_vertex!(Vertex, vertex, tex_coords, normal, barycentric, face_color);
|
||||
|
||||
/// A part of a 3D model.
|
||||
///
|
||||
@@ -534,7 +535,12 @@ impl Model {
|
||||
|
||||
let mut vertex_buffer = vec![];
|
||||
for face in part.faces() {
|
||||
for &&v in &[&face.a, &face.b, &face.c] {
|
||||
let v0 = vertices[face.a.vertex];
|
||||
let v1 = vertices[face.b.vertex];
|
||||
let v2 = vertices[face.c.vertex];
|
||||
let barycenter = (v0 + v1 + v2) / 3.0;
|
||||
|
||||
for (index, &&v) in [&face.a, &face.b, &face.c].iter().enumerate() {
|
||||
let vertex = vertices[v.vertex].into();
|
||||
let tex_coord = if let Some(tex_index) = v.texture_coordinate {
|
||||
texture_coordinates[tex_index].into()
|
||||
@@ -542,6 +548,14 @@ impl Model {
|
||||
[0.0, 0.0]
|
||||
};
|
||||
|
||||
|
||||
let barycentric = match index {
|
||||
0 => [1.0, 0.0, 0.0],
|
||||
1 => [0.0, 1.0, 0.0],
|
||||
2 => [0.0, 0.0, 1.0],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let normal = if let Some(normal_index) = v.normal {
|
||||
normals[normal_index].into()
|
||||
} else {
|
||||
@@ -564,10 +578,11 @@ impl Model {
|
||||
];
|
||||
|
||||
vertex_buffer.push(Vertex {
|
||||
vertex: vertex,
|
||||
tex_coords: tex_coord,
|
||||
normal: normal,
|
||||
face_color: [r, g, b],
|
||||
vertex: vertex,
|
||||
tex_coords: tex_coord,
|
||||
normal: normal,
|
||||
barycentric: barycentric,
|
||||
face_color: [r, g, b],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ fn main() {
|
||||
let context = glutin::ContextBuilder::new().with_depth_buffer(24);
|
||||
let display = Display::new(window, context, &events_loop).unwrap();
|
||||
let mut renderer = Renderer::new(display);
|
||||
renderer.set_clear_color(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
let mut scene = Scene::new();
|
||||
let mut before;
|
||||
|
||||
Reference in New Issue
Block a user