-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minecraft: Update voxelizer + thematic surfaces (#564)
### Description(変更内容) - ボクセルに任意の値を持たせられるようになった MIERUNE/dda-voxelize-rs#6 ので、それを利用する。 - → 地物ごとにボクセライザを作る必要がなくなる。 - 上記のデモも兼ねて、Thematic surfaces の類(壁とか屋根とか窓とか)で塗り分けられるように変更する。 - ボクセライズアルゴリズムの都合で、窓より外側に壁が塗られてしまうこともある、などの問題はありますが、これの回避は難しそう。 ![Untitled](https://github.com/MIERUNE/plateau-gis-converter/assets/5351911/150016c4-955e-4c8c-a55d-6ae798b8bbeb)
- Loading branch information
Showing
3 changed files
with
295 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,139 @@ | ||
use std::collections::HashMap; | ||
|
||
pub fn get_block_for_typename() -> HashMap<&'static str, &'static str> { | ||
let mut typename_blocks: HashMap<&'static str, &'static str> = HashMap::new(); | ||
#[derive(Clone)] | ||
pub struct Voxel { | ||
pub block_name: &'static str, | ||
pub priority: u8, | ||
} | ||
|
||
typename_blocks.insert("bldg:Building", "iron_block"); | ||
typename_blocks.insert("tran:Road", "gray_wool"); | ||
typename_blocks.insert("tran:Railway", "granite"); | ||
typename_blocks.insert("tran:Track", "stone_bricks"); | ||
typename_blocks.insert("tran:Square", "smooth_stone"); | ||
typename_blocks.insert("uro:Waterway", "cyan_stained_glass"); | ||
typename_blocks.insert("luse:LandUse", "coarse_dirt"); | ||
typename_blocks.insert("frn:CityFurniture", "quartz_block"); | ||
typename_blocks.insert("veg:PlantCover", "moss_block"); | ||
typename_blocks.insert("veg:SolitaryVegetationObject", "oak_leaves"); | ||
typename_blocks.insert("wtr:WaterBody", "water"); | ||
typename_blocks.insert("dem:ReliefFeature", "stone"); | ||
typename_blocks.insert("brid:Bridge", "polished_andesite"); | ||
typename_blocks.insert("tun:Tunnel", "cobblestone"); | ||
typename_blocks.insert("urf:UseDistrict", "green_stained_glass"); | ||
typename_blocks.insert("urf:FirePreventionDistrict", "red_stained_glass"); | ||
typename_blocks.insert("urf:SedimentDisasterProneArea", "yellow_stained_glass"); | ||
typename_blocks.insert("urf:Zone", "magenta_stained_glass"); | ||
impl Voxel { | ||
fn new(block_name: &'static str, priority: u8) -> Voxel { | ||
Voxel { | ||
block_name, | ||
priority, | ||
} | ||
} | ||
} | ||
|
||
typename_blocks | ||
pub struct DefaultBlockResolver { | ||
typename_blocks: HashMap<&'static str, Voxel>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
impl DefaultBlockResolver { | ||
pub fn new() -> DefaultBlockResolver { | ||
let mut typename_blocks: HashMap<&'static str, Voxel> = HashMap::new(); | ||
|
||
#[test] | ||
fn test_get_typename_block() { | ||
let typename_blocks = get_block_for_typename(); | ||
assert_eq!(typename_blocks.get("bldg:Building"), Some(&"iron_block")); | ||
assert_eq!(typename_blocks.get("tran:Road"), Some(&"gray_wool")); | ||
assert_eq!(typename_blocks.get("tran:Railway"), Some(&"granite")); | ||
assert_eq!(typename_blocks.get("tran:Track"), Some(&"stone_bricks")); | ||
assert_eq!(typename_blocks.get("tran:Square"), Some(&"smooth_stone")); | ||
assert_eq!( | ||
typename_blocks.get("uro:Waterway"), | ||
Some(&"cyan_stained_glass") | ||
); | ||
assert_eq!(typename_blocks.get("luse:LandUse"), Some(&"coarse_dirt")); | ||
assert_eq!( | ||
typename_blocks.get("frn:CityFurniture"), | ||
Some(&"quartz_block") | ||
); | ||
assert_eq!(typename_blocks.get("veg:PlantCover"), Some(&"moss_block")); | ||
assert_eq!( | ||
typename_blocks.get("veg:SolitaryVegetationObject"), | ||
Some(&"oak_leaves") | ||
typename_blocks.insert( | ||
"bldg:BuildingInstallation", | ||
Voxel::new("light_gray_concrete", 40), | ||
); | ||
assert_eq!(typename_blocks.get("wtr:WaterBody"), Some(&"water")); | ||
assert_eq!(typename_blocks.get("dem:ReliefFeature"), Some(&"stone")); | ||
assert_eq!( | ||
typename_blocks.get("brid:Bridge"), | ||
Some(&"polished_andesite") | ||
); | ||
assert_eq!(typename_blocks.get("tun:Tunnel"), Some(&"cobblestone")); | ||
assert_eq!( | ||
typename_blocks.get("urf:UseDistrict"), | ||
Some(&"green_stained_glass") | ||
); | ||
assert_eq!( | ||
typename_blocks.get("urf:FirePreventionDistrict"), | ||
Some(&"red_stained_glass") | ||
); | ||
assert_eq!( | ||
typename_blocks.get("urf:SedimentDisasterProneArea"), | ||
Some(&"yellow_stained_glass") | ||
typename_blocks.insert("bldg:OuterFloorSurface", Voxel::new("white_wool", 40)); | ||
typename_blocks.insert("bldg:OuterCeilingSurface", Voxel::new("white_wool", 40)); | ||
typename_blocks.insert("bldg:CeilingSurface", Voxel::new("white_wool", 20)); | ||
typename_blocks.insert("bldg:FloorSurface", Voxel::new("white_wool", 20)); | ||
typename_blocks.insert("bldg:WallSurface", Voxel::new("iron_block", 20)); | ||
|
||
typename_blocks.insert("tran:Road", Voxel::new("gray_wool", 10)); | ||
typename_blocks.insert("tran:Railway", Voxel::new("granite", 10)); | ||
typename_blocks.insert("tran:Track", Voxel::new("stone_bricks", 10)); | ||
typename_blocks.insert("tran:Square", Voxel::new("smooth_stone", 10)); | ||
|
||
typename_blocks.insert("veg:PlantCover", Voxel::new("moss_block", 10)); | ||
typename_blocks.insert("veg:SolitaryVegetationObject", Voxel::new("oak_leaves", 10)); | ||
|
||
typename_blocks.insert("uro:Waterway", Voxel::new("cyan_stained_glass", 10)); | ||
typename_blocks.insert("luse:LandUse", Voxel::new("coarse_dirt", 10)); | ||
typename_blocks.insert("dem:ReliefFeature", Voxel::new("stone", 10)); | ||
typename_blocks.insert("urf:UseDistrict", Voxel::new("green_stained_glass", 1)); | ||
typename_blocks.insert( | ||
"urf:FirePreventionDistrict", | ||
Voxel::new("red_stained_glass", 1), | ||
); | ||
assert_eq!( | ||
typename_blocks.get("urf:Zone"), | ||
Some(&"magenta_stained_glass") | ||
typename_blocks.insert( | ||
"urf:SedimentDisasterProneArea", | ||
Voxel::new("yellow_stained_glass", 1), | ||
); | ||
typename_blocks.insert("urf:Zone", Voxel::new("magenta_stained_glass", 1)); | ||
|
||
DefaultBlockResolver { typename_blocks } | ||
} | ||
|
||
pub fn resolve(&self, typename: &str) -> Option<Voxel> { | ||
let (prefix, local_name) = typename.split_once(':')?; | ||
|
||
match local_name { | ||
"ClosureSurface" => return None, | ||
"InteriorWallSurface" => return None, | ||
"Window" | "Door" => return Some(Voxel::new("cyan_stained_glass", 100)), | ||
_ => {} | ||
}; | ||
|
||
if let Some(voxel) = self.typename_blocks.get(typename) { | ||
return Some(voxel.clone()); | ||
} | ||
|
||
match prefix { | ||
"bldg" => return Some(Voxel::new("iron_block", 30)), | ||
"brid" => return Some(Voxel::new("polished_andesite", 30)), | ||
"tun" => return Some(Voxel::new("cobblestone", 20)), | ||
"frn" => return Some(Voxel::new("quartz_block", 20)), | ||
"tran" => return Some(Voxel::new("gray_wool", 10)), | ||
"wtr" => return Some(Voxel::new("water", 10)), | ||
_ => {} | ||
} | ||
|
||
Some(Voxel::new("white_wool", 0)) | ||
} | ||
} | ||
|
||
// #[cfg(test)] | ||
// mod tests { | ||
// use super::*; | ||
// | ||
// #[test] | ||
// fn test_get_typename_block() { | ||
// let typename_blocks = get_block_for_typename(); | ||
// assert_eq!(typename_blocks.get("bldg:Building"), Some(&"iron_block")); | ||
// assert_eq!(typename_blocks.get("tran:Road"), Some(&"gray_wool")); | ||
// assert_eq!(typename_blocks.get("tran:Railway"), Some(&"granite")); | ||
// assert_eq!(typename_blocks.get("tran:Track"), Some(&"stone_bricks")); | ||
// assert_eq!(typename_blocks.get("tran:Square"), Some(&"smooth_stone")); | ||
// assert_eq!( | ||
// typename_blocks.get("uro:Waterway"), | ||
// Some(&"cyan_stained_glass") | ||
// ); | ||
// assert_eq!(typename_blocks.get("luse:LandUse"), Some(&"coarse_dirt")); | ||
// assert_eq!( | ||
// typename_blocks.get("frn:CityFurniture"), | ||
// Some(&"quartz_block") | ||
// ); | ||
// assert_eq!(typename_blocks.get("veg:PlantCover"), Some(&"moss_block")); | ||
// assert_eq!( | ||
// typename_blocks.get("veg:SolitaryVegetationObject"), | ||
// Some(&"oak_leaves") | ||
// ); | ||
// assert_eq!(typename_blocks.get("wtr:WaterBody"), Some(&"water")); | ||
// assert_eq!(typename_blocks.get("dem:ReliefFeature"), Some(&"stone")); | ||
// assert_eq!( | ||
// typename_blocks.get("brid:Bridge"), | ||
// Some(&"polished_andesite") | ||
// ); | ||
// assert_eq!(typename_blocks.get("tun:Tunnel"), Some(&"cobblestone")); | ||
// assert_eq!( | ||
// typename_blocks.get("urf:UseDistrict"), | ||
// Some(&"green_stained_glass") | ||
// ); | ||
// assert_eq!( | ||
// typename_blocks.get("urf:FirePreventionDistrict"), | ||
// Some(&"red_stained_glass") | ||
// ); | ||
// assert_eq!( | ||
// typename_blocks.get("urf:SedimentDisasterProneArea"), | ||
// Some(&"yellow_stained_glass") | ||
// ); | ||
// assert_eq!( | ||
// typename_blocks.get("urf:Zone"), | ||
// Some(&"magenta_stained_glass") | ||
// ); | ||
// } | ||
// } |
Oops, something went wrong.