2019-01-13 20:53:55 +00:00
|
|
|
// Library
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
// Project
|
2019-01-23 20:01:58 +00:00
|
|
|
use common::{
|
|
|
|
figure::Segment,
|
2019-04-28 17:12:45 +00:00
|
|
|
vol::{ReadVol, SizedVol, Vox},
|
2019-01-13 20:53:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Crate
|
|
|
|
use crate::{
|
2019-04-28 17:12:45 +00:00
|
|
|
mesh::{ao, Meshable},
|
|
|
|
render::{self, FigurePipeline, Mesh, Quad},
|
2019-01-13 20:53:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type FigureVertex = <FigurePipeline as render::Pipeline>::Vertex;
|
|
|
|
|
2019-04-28 17:12:45 +00:00
|
|
|
fn create_vertex(origin: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>) -> FigureVertex {
|
|
|
|
FigureVertex::new(origin, norm, col, 0)
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Meshable for Segment {
|
|
|
|
type Pipeline = FigurePipeline;
|
2019-01-23 20:01:58 +00:00
|
|
|
type Supplement = Vec3<f32>;
|
2019-01-13 20:53:55 +00:00
|
|
|
|
2019-01-23 20:01:58 +00:00
|
|
|
fn generate_mesh(&self, offs: Self::Supplement) -> Mesh<Self::Pipeline> {
|
2019-01-13 20:53:55 +00:00
|
|
|
let mut mesh = Mesh::new();
|
|
|
|
|
|
|
|
for pos in self.iter_positions() {
|
2019-04-28 17:12:45 +00:00
|
|
|
if let Some(col) = self.get(pos).ok().and_then(|vox| vox.get_color()) {
|
2019-01-13 20:53:55 +00:00
|
|
|
let col = col.map(|e| e as f32 / 255.0);
|
|
|
|
|
2019-04-28 17:12:45 +00:00
|
|
|
ao::push_vox_verts_ao(
|
|
|
|
&mut mesh,
|
|
|
|
self,
|
|
|
|
pos,
|
|
|
|
offs + pos.map(|e| e as f32),
|
|
|
|
col,
|
|
|
|
create_vertex,
|
|
|
|
);
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh
|
|
|
|
}
|
|
|
|
}
|