veloren/voxygen/src/mesh/segment.rs

47 lines
1.1 KiB
Rust
Raw Normal View History

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