move sample() to returning VolMap, incomplete VolMap meshing code

Former-commit-id: 77d3db6c3bf28364089647802f83d2d00f3a152d
This commit is contained in:
sxv20_ 2019-05-12 19:33:39 +01:00 committed by Joshua Barretto
parent e20c2a1e00
commit 592477752e
2 changed files with 40 additions and 4 deletions

View File

@ -4,8 +4,8 @@ use vek::*;
// Project
use common::{
terrain::Block,
vol::{ReadVol, SizedVol, Vox},
volumes::dyna::Dyna,
vol::{ReadVol, SizedVol, VolSize, Vox},
volumes::{dyna::Dyna, vol_map::VolMap},
};
// Crate
@ -43,3 +43,38 @@ impl<M> Meshable for Dyna<Block, M> {
mesh
}
}
impl<S: VolSize + Clone, M: Clone> Meshable for VolMap<Block, S, M> {
type Pipeline = TerrainPipeline;
type Supplement = Aabb<i32>;
fn generate_mesh(&self, range: Self::Supplement) -> Mesh<Self::Pipeline> {
let mut mesh = Mesh::new();
let mut last_chunk_pos = self.pos_key(range.min);
let mut last_chunk = self.get_key(last_chunk_pos);
let size = range.max - range.min;
for x in 1..(size.x - 1) {
for y in 1..(size.y - 1) {
for z in 1..(size.z - 1) {
let pos = Vec3::new(x, y, z);
let new_chunk_pos = self.pos_key(range.min + pos);
if last_chunk_pos != new_chunk_pos {
last_chunk = self.get_key(new_chunk_pos);
last_chunk_pos = new_chunk_pos;
}
let offs = pos.map(|e| e as f32 - 1.0);
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, col, TerrainVertex::new);
}
}
}
}
mesh
}
}

View File

@ -38,10 +38,11 @@ fn mesh_worker(
pos: Vec3<i32>,
started_tick: u64,
volume: <TerrainMap as SampleVol>::Sample,
supplement: Aabb<i32>,
) -> MeshWorkerResponse {
MeshWorkerResponse {
pos,
mesh: volume.generate_mesh(()),
mesh: volume.generate_mesh(supplement),
started_tick,
}
}
@ -146,7 +147,7 @@ impl Terrain {
// Queue the worker thread
client.thread_pool().execute(move || {
send.send(mesh_worker(pos, current_tick, volume))
send.send(mesh_worker(pos, current_tick, volume, aabb))
.expect("Failed to send chunk mesh to main thread");
});
todo.active_worker = true;