veloren/voxygen/src/mesh/segment.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

use crate::{
mesh::{vol, Meshable},
render::{self, FigurePipeline, Mesh},
};
use common::{
figure::Segment,
2019-08-04 19:54:08 +00:00
util::{linear_to_srgb, srgb_to_linear},
vol::{ReadVol, SizedVol},
};
use vek::*;
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-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);
vol::push_vox_verts(
&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| {
2019-08-04 19:54:08 +00:00
FigureVertex::new(
origin,
norm,
linear_to_srgb(srgb_to_linear(col) * ao * light),
0,
)
2019-06-19 14:55:26 +00:00
},
true,
2019-06-18 11:33:18 +00:00
&[[[1.0; 3]; 3]; 3],
);
}
}
mesh
}
}