From 7091557b82b184438047caf2424a774dffc98e21 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 28 Apr 2019 23:34:58 +0200 Subject: [PATCH] Rename mod ao to vol Former-commit-id: ef126e03761b18151594780777fa27e94efe24d7 --- voxygen/src/mesh/mod.rs | 2 +- voxygen/src/mesh/segment.rs | 4 +-- voxygen/src/mesh/terrain.rs | 4 +-- voxygen/src/mesh/{ao.rs => vol.rs} | 40 ++++++++++++++++-------------- 4 files changed, 26 insertions(+), 24 deletions(-) rename voxygen/src/mesh/{ao.rs => vol.rs} (80%) diff --git a/voxygen/src/mesh/mod.rs b/voxygen/src/mesh/mod.rs index e9ff529c9d..7fb9f8e43d 100644 --- a/voxygen/src/mesh/mod.rs +++ b/voxygen/src/mesh/mod.rs @@ -1,4 +1,4 @@ -mod ao; +mod vol; pub mod segment; pub mod terrain; diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 97333017ef..620adcfc30 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -9,7 +9,7 @@ use common::{ // Crate use crate::{ - mesh::{ao, Meshable}, + mesh::{vol, Meshable}, render::{self, FigurePipeline, Mesh, Quad}, }; @@ -30,7 +30,7 @@ impl Meshable for Segment { 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( + vol::push_vox_verts( &mut mesh, self, pos, diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 7e4334b449..a9157419e7 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -10,7 +10,7 @@ use common::{ // Crate use crate::{ - mesh::{ao, Meshable}, + mesh::{vol, Meshable}, render::{self, Mesh, Quad, TerrainPipeline}, }; @@ -36,7 +36,7 @@ impl Meshable for Dyna { 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, col, TerrainVertex::new); + vol::push_vox_verts(&mut mesh, self, pos, offs, col, TerrainVertex::new); } } diff --git a/voxygen/src/mesh/ao.rs b/voxygen/src/mesh/vol.rs similarity index 80% rename from voxygen/src/mesh/ao.rs rename to voxygen/src/mesh/vol.rs index 8edeaec63b..ea47d9bde5 100644 --- a/voxygen/src/mesh/ao.rs +++ b/voxygen/src/mesh/vol.rs @@ -10,7 +10,7 @@ use crate::render::{ /// Given a volume, a position and the cardinal directions, compute each vertex' AO value /// `dirs` should be a slice of length 5 so that the sliding window of size 2 over the slice /// yields each vertex' adjacent positions. -fn get_quad_ao(vol: &V, pos: Vec3, dirs: &[Vec3]) -> Vec4 { +fn get_ao_quad(vol: &V, pos: Vec3, dirs: &[Vec3]) -> Vec4 { dirs.windows(2) .map(|offs| { let (s1, s2) = ( @@ -36,17 +36,15 @@ fn get_quad_ao(vol: &V, pos: Vec3, dirs: &[Vec3]) -> Vec4< .collect::>() } -type VertexCons = fn(Vec3, Vec3, Rgb) -> P::Vertex; - // Utility function -fn create_quad( +fn create_quad, Vec3, Rgb) -> P::Vertex>( origin: Vec3, unit_x: Vec3, unit_y: Vec3, norm: Vec3, col: Rgb, ao: Vec4, - vcons: VertexCons

, + vcons: &F, ) -> Quad

{ let ao_scale = 1.0; let dark = col * (1.0 - ao_scale); @@ -68,13 +66,17 @@ fn create_quad( } } -pub fn push_vox_verts_ao( +pub fn push_vox_verts< + V: ReadVol, + P: Pipeline, + F: Fn(Vec3, Vec3, Rgb) -> P::Vertex, +>( mesh: &mut Mesh

, vol: &V, pos: Vec3, offs: Vec3, col: Rgb, - vcons: VertexCons

, + vcons: F, ) { let (x, y, z) = (Vec3::unit_x(), Vec3::unit_y(), Vec3::unit_z()); @@ -90,8 +92,8 @@ pub fn push_vox_verts_ao( Vec3::unit_y(), -Vec3::unit_x(), col, - get_quad_ao(vol, pos - Vec3::unit_x(), &[-z, -y, z, y, -z]), - vcons, + get_ao_quad(vol, pos - Vec3::unit_x(), &[-z, -y, z, y, -z]), + &vcons, )); } // +x @@ -106,8 +108,8 @@ pub fn push_vox_verts_ao( Vec3::unit_z(), Vec3::unit_x(), col, - get_quad_ao(vol, pos + Vec3::unit_x(), &[-y, -z, y, z, -y]), - vcons, + get_ao_quad(vol, pos + Vec3::unit_x(), &[-y, -z, y, z, -y]), + &vcons, )); } // -y @@ -122,8 +124,8 @@ pub fn push_vox_verts_ao( Vec3::unit_z(), -Vec3::unit_y(), col, - get_quad_ao(vol, pos - Vec3::unit_y(), &[-x, -z, x, z, -x]), - vcons, + get_ao_quad(vol, pos - Vec3::unit_y(), &[-x, -z, x, z, -x]), + &vcons, )); } // +y @@ -138,8 +140,8 @@ pub fn push_vox_verts_ao( Vec3::unit_x(), Vec3::unit_y(), col, - get_quad_ao(vol, pos + Vec3::unit_y(), &[-z, -x, z, x, -z]), - vcons, + get_ao_quad(vol, pos + Vec3::unit_y(), &[-z, -x, z, x, -z]), + &vcons, )); } // -z @@ -154,8 +156,8 @@ pub fn push_vox_verts_ao( Vec3::unit_x(), -Vec3::unit_z(), col, - get_quad_ao(vol, pos - Vec3::unit_z(), &[-y, -x, y, x, -y]), - vcons, + get_ao_quad(vol, pos - Vec3::unit_z(), &[-y, -x, y, x, -y]), + &vcons, )); } // +z @@ -170,8 +172,8 @@ pub fn push_vox_verts_ao( Vec3::unit_y(), Vec3::unit_z(), col, - get_quad_ao(vol, pos + Vec3::unit_z(), &[-x, -y, x, y, -x]), - vcons, + get_ao_quad(vol, pos + Vec3::unit_z(), &[-x, -y, x, y, -x]), + &vcons, )); } }