2019-01-13 20:53:55 +00:00
|
|
|
use crate::{
|
2019-04-28 21:34:58 +00:00
|
|
|
mesh::{vol, Meshable},
|
2019-06-06 14:48:41 +00:00
|
|
|
render::{self, FigurePipeline, Mesh},
|
2019-01-13 20:53:55 +00:00
|
|
|
};
|
2019-06-06 14:48:41 +00:00
|
|
|
use common::{
|
|
|
|
figure::Segment,
|
|
|
|
vol::{ReadVol, SizedVol},
|
|
|
|
};
|
|
|
|
use vek::*;
|
2019-01-13 20:53:55 +00:00
|
|
|
|
|
|
|
type FigureVertex = <FigurePipeline as render::Pipeline>::Vertex;
|
|
|
|
|
|
|
|
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 21:34:58 +00:00
|
|
|
vol::push_vox_verts(
|
2019-04-28 17:12:45 +00:00
|
|
|
&mut mesh,
|
|
|
|
self,
|
|
|
|
pos,
|
|
|
|
offs + pos.map(|e| e as f32),
|
|
|
|
col,
|
2019-06-19 14:55:26 +00:00
|
|
|
|origin, norm, col, ao, light| {
|
|
|
|
FigureVertex::new(origin, norm, col * ao * light, 0)
|
|
|
|
},
|
2019-05-13 12:08:17 +00:00
|
|
|
true,
|
2019-06-18 11:33:18 +00:00
|
|
|
&[[[1.0; 3]; 3]; 3],
|
2019-04-28 17:12:45 +00:00
|
|
|
);
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh
|
|
|
|
}
|
|
|
|
}
|