From c213e7d490a73a27a44072e00a07efb886413103 Mon Sep 17 00:00:00 2001 From: yanorei32 Date: Tue, 23 Dec 2025 15:07:42 +0900 Subject: [PATCH 1/3] Add area_code information in map vertex --- asset-preprocessor/src/parse_shapefile.rs | 40 +++++++++++++++-------- renderer-assets/src/lib.rs | 2 +- renderer/src/worker/resources.rs | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/asset-preprocessor/src/parse_shapefile.rs b/asset-preprocessor/src/parse_shapefile.rs index 5abb14b..2b2db8b 100644 --- a/asset-preprocessor/src/parse_shapefile.rs +++ b/asset-preprocessor/src/parse_shapefile.rs @@ -13,8 +13,8 @@ use renderer_types::*; use crate::math::*; struct VertexBuffer { - buffer: Vec<(Of32, Of32)>, - dict: HashMap<(Of32, Of32), usize>, + buffer: Vec<(Of32, Of32, u32)>, + dict: HashMap<(Of32, Of32, u32), usize>, } impl VertexBuffer { @@ -25,7 +25,7 @@ impl VertexBuffer { } } - fn insert(&mut self, v: (Of32, Of32)) -> usize { + fn insert(&mut self, v: (Of32, Of32, u32)) -> usize { match self.dict.get(&v) { Some(index) => *index, None => { @@ -37,8 +37,11 @@ impl VertexBuffer { } } - fn into_buffer(self) -> Vec<(f32, f32)> { - self.buffer.into_iter().map(|(x, y)| (x.0, y.0)).collect() + fn into_buffer(self) -> Vec<(f32, f32, u32)> { + self.buffer + .into_iter() + .map(|(x, y, code)| (x.0, y.0, code)) + .collect() } } @@ -206,7 +209,7 @@ pub fn read( ) -> ( HashMap>, // area_bounding_box HashMap>, // area_centers - Vec<(f32, f32)>, // vertex_buffer + Vec<(f32, f32, u32)>, // vertex_buffer Vec, // map_indices Vec>, // area_lines Vec>, // pref_lines @@ -229,13 +232,22 @@ pub fn read( .map(|area_rings| (area_rings.area_code, area_rings.bounding_box)) .collect(); - let map_indices = shapefile - .entries - .iter() - .flat_map(|area_rings| &area_rings.rings) - .flat_map(|r| r.triangulate()) - .map(|p| vertex_buffer.insert(p.into()) as u32) - .collect(); + let mut map_indices = vec![]; + + for entry in &shapefile.entries { + let area_code = entry.area_code; + + map_indices.extend( + entry + .rings + .iter() + .flat_map(|ring| ring.triangulate()) + .map(|p| { + let p = Into::<(Of32, Of32)>::into(p); + vertex_buffer.insert((p.0, p.1, area_code)) as u32 + }), + ); + } let references = PointReferences::tally_of(&shapefile, area_code__pref_code); @@ -390,7 +402,7 @@ fn gen_lod( let l = l.0.iter() .map(|c| (Of32::from(c.x as f32), Of32::from(c.y as f32))) - .map(|v| vertex_buffer.insert(v) as u32); + .map(|v| vertex_buffer.insert((v.0, v.1, codes::UNNUMBERED_AREA)) as u32); v.extend(l); v.push(0); } diff --git a/renderer-assets/src/lib.rs b/renderer-assets/src/lib.rs index 8ea6207..934c7ec 100644 --- a/renderer-assets/src/lib.rs +++ b/renderer-assets/src/lib.rs @@ -8,7 +8,7 @@ use renderer_types::*; pub struct QueryInterface; pub struct Geometries { - pub vertices: &'static [(f32, f32)], + pub vertices: &'static [(f32, f32, u32)], pub map_triangles: &'static [u32], pub area_lines: &'static [&'static [u32]], pub pref_lines: &'static [&'static [u32]], diff --git a/renderer/src/worker/resources.rs b/renderer/src/worker/resources.rs index 0ef058f..033f04d 100644 --- a/renderer/src/worker/resources.rs +++ b/renderer/src/worker/resources.rs @@ -47,7 +47,7 @@ impl Buffer { .vertices .iter() .map(|v| MapVertex { - position: Vertex::::from(*v).to_slice() + position: Vertex::::from((v.0, v.1)).to_slice() }) .collect(); From bade3f5de1ca2610455a301283f92935926bb335 Mon Sep 17 00:00:00 2001 From: yanorei32 Date: Wed, 24 Dec 2025 12:27:07 +0900 Subject: [PATCH 2/3] Split VERTICES to map_vertices and line_vertices --- asset-preprocessor/src/parse_shapefile.rs | 36 ++++++++++++----------- renderer-assets/build.rs | 15 ++++++++-- renderer-assets/src/lib.rs | 6 ++-- renderer/src/worker/drawer_map.rs | 6 ++-- renderer/src/worker/resources.rs | 22 ++++++++++---- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/asset-preprocessor/src/parse_shapefile.rs b/asset-preprocessor/src/parse_shapefile.rs index 2b2db8b..ed83eb1 100644 --- a/asset-preprocessor/src/parse_shapefile.rs +++ b/asset-preprocessor/src/parse_shapefile.rs @@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet}; use std::path::Path; +use std::hash::Hash; use geo::Simplify; use itertools::Itertools; @@ -12,12 +13,12 @@ use renderer_types::*; use crate::math::*; -struct VertexBuffer { - buffer: Vec<(Of32, Of32, u32)>, - dict: HashMap<(Of32, Of32, u32), usize>, +struct VertexBuffer { + buffer: Vec, + dict: HashMap, } -impl VertexBuffer { +impl VertexBuffer { fn new() -> Self { Self { buffer: Default::default(), @@ -25,7 +26,7 @@ impl VertexBuffer { } } - fn insert(&mut self, v: (Of32, Of32, u32)) -> usize { + fn insert(&mut self, v: T) -> usize { match self.dict.get(&v) { Some(index) => *index, None => { @@ -37,11 +38,8 @@ impl VertexBuffer { } } - fn into_buffer(self) -> Vec<(f32, f32, u32)> { + fn into_buffer(self) -> Vec { self.buffer - .into_iter() - .map(|(x, y, code)| (x.0, y.0, code)) - .collect() } } @@ -209,7 +207,8 @@ pub fn read( ) -> ( HashMap>, // area_bounding_box HashMap>, // area_centers - Vec<(f32, f32, u32)>, // vertex_buffer + Vec<(f32, f32, u32)>, // map_vertex_buffer + Vec<(f32, f32)>, // line_vertex_buffer Vec, // map_indices Vec>, // area_lines Vec>, // pref_lines @@ -219,7 +218,7 @@ pub fn read( "../assets/shapefile/earthquake_detailed/earthquake_detailed_simplified.shp", "../assets/shapefile/earthquake_detailed/earthquake_detailed_simplified.dbf", ); - let mut vertex_buffer = VertexBuffer::new(); + let mut map_vertex_buffer = VertexBuffer::new(); // @Siro_256 にゃ~っ…! (ΦωΦ) @@ -244,7 +243,7 @@ pub fn read( .flat_map(|ring| ring.triangulate()) .map(|p| { let p = Into::<(Of32, Of32)>::into(p); - vertex_buffer.insert((p.0, p.1, area_code)) as u32 + map_vertex_buffer.insert((p.0, p.1, area_code)) as u32 }), ); } @@ -320,8 +319,10 @@ pub fn read( (100.0_f32.powf(0.24), 0.117), ]; - let area_lines = gen_lod(&mut vertex_buffer, &lod_details, &area_lines); - let pref_lines = gen_lod(&mut vertex_buffer, &lod_details, &pref_lines); + let mut line_vertex_buffer = VertexBuffer::new(); + + let area_lines = gen_lod(&mut line_vertex_buffer, &lod_details, &area_lines); + let pref_lines = gen_lod(&mut line_vertex_buffer, &lod_details, &pref_lines); let scale_level_map = lod_details .into_iter() @@ -336,7 +337,8 @@ pub fn read( ( area_bounding_box, area_centers, - vertex_buffer.into_buffer(), + map_vertex_buffer.into_buffer().into_iter().map(|(x, y, code)| (x.0, y.0, code)).collect(), + line_vertex_buffer.into_buffer().into_iter().map(|(x, y)| (x.0, y.0)).collect(), map_indices, area_lines, pref_lines, @@ -384,7 +386,7 @@ fn cut_rings(rings: &[&Ring], cut_points: &[Point]) -> Vec { } fn gen_lod( - vertex_buffer: &mut VertexBuffer, + vertex_buffer: &mut VertexBuffer<(Of32, Of32)>, lod_details: &[(f32, f64)], base_lines: &[&Line], ) -> Vec> { @@ -402,7 +404,7 @@ fn gen_lod( let l = l.0.iter() .map(|c| (Of32::from(c.x as f32), Of32::from(c.y as f32))) - .map(|v| vertex_buffer.insert((v.0, v.1, codes::UNNUMBERED_AREA)) as u32); + .map(|v| vertex_buffer.insert(v) as u32); v.extend(l); v.push(0); } diff --git a/renderer-assets/build.rs b/renderer-assets/build.rs index 304eefe..373826b 100644 --- a/renderer-assets/build.rs +++ b/renderer-assets/build.rs @@ -22,8 +22,16 @@ fn main() { ) = station_codes_parser::read(&s); #[allow(non_snake_case)] - let (area_code__bbox, area_code__centers, vertices, indices, area_lines, pref_lines, scale_level_map) = - parse_shapefile::read(&area_code__pref_code); + let ( + area_code__bbox, + area_code__centers, + map_vertices, + line_vertices, + indices, + area_lines, + pref_lines, + scale_level_map, + ) = parse_shapefile::read(&area_code__pref_code); // let areas: HashMap = area_code__bbox @@ -55,7 +63,8 @@ fn main() { const_declaration!(INTENSITY_STATION_POSITIONS = intensity_station_minimized), const_declaration!(AREAS = areas), const_declaration!(STATION_CODES = station_code__index), - const_declaration!(VERTICES = vertices), + const_declaration!(MAP_VERTICES = map_vertices), + const_declaration!(LINE_VERTICES = line_vertices), const_declaration!(MAP_TRIANGLES = indices), const_declaration!(AREA_LINES = area_lines), const_declaration!(PREF_LINES = pref_lines), diff --git a/renderer-assets/src/lib.rs b/renderer-assets/src/lib.rs index 934c7ec..02a3a6b 100644 --- a/renderer-assets/src/lib.rs +++ b/renderer-assets/src/lib.rs @@ -8,8 +8,9 @@ use renderer_types::*; pub struct QueryInterface; pub struct Geometries { - pub vertices: &'static [(f32, f32, u32)], + pub map_vertices: &'static [(f32, f32, u32)], pub map_triangles: &'static [u32], + pub line_vertices: &'static [(f32, f32)], pub area_lines: &'static [&'static [u32]], pub pref_lines: &'static [&'static [u32]], } @@ -22,8 +23,9 @@ pub struct LakeGeometries { impl QueryInterface { pub fn geometries() -> Geometries { Geometries { - vertices: VERTICES, + map_vertices: MAP_VERTICES, map_triangles: MAP_TRIANGLES, + line_vertices: LINE_VERTICES, area_lines: AREA_LINES, pref_lines: PREF_LINES, } diff --git a/renderer/src/worker/drawer_map.rs b/renderer/src/worker/drawer_map.rs index a762a72..fd429c7 100644 --- a/renderer/src/worker/drawer_map.rs +++ b/renderer/src/worker/drawer_map.rs @@ -21,7 +21,7 @@ pub fn draw(frame_context: &FrameContex .map .draw( frame_context.surface.borrow_mut().deref_mut(), - &resources.buffer.vertex, + &resources.buffer.map_vertex, &resources.buffer.map, &MapUniform { aspect_ratio, @@ -55,7 +55,7 @@ pub fn draw(frame_context: &FrameContex .border_line .draw( frame_context.surface.borrow_mut().deref_mut(), - &resources.buffer.vertex, + &resources.buffer.line_vertex, resources.buffer.get_area_line_by_scale(scale).unwrap(), &BorderLineUniform { dimension, @@ -73,7 +73,7 @@ pub fn draw(frame_context: &FrameContex .border_line .draw( frame_context.surface.borrow_mut().deref_mut(), - &resources.buffer.vertex, + &resources.buffer.line_vertex, resources.buffer.get_pref_line_by_scale(scale).unwrap(), &BorderLineUniform { dimension, diff --git a/renderer/src/worker/resources.rs b/renderer/src/worker/resources.rs index 033f04d..b2cd689 100644 --- a/renderer/src/worker/resources.rs +++ b/renderer/src/worker/resources.rs @@ -33,7 +33,8 @@ impl Resources<'_> { #[derive(Debug)] pub struct Buffer { - pub vertex: VertexBuffer, + pub map_vertex: VertexBuffer, + pub line_vertex: VertexBuffer, area_line: Vec>, pref_line: Vec>, pub map: IndexBuffer, @@ -43,15 +44,25 @@ impl Buffer { fn load(facade: &F) -> Self { let geom = renderer_assets::QueryInterface::geometries(); - let vertices: Vec<_> = geom - .vertices + let map_vertices: Vec<_> = geom + .map_vertices .iter() .map(|v| MapVertex { position: Vertex::::from((v.0, v.1)).to_slice() }) .collect(); - let vertex = VertexBuffer::new(facade, &vertices).unwrap(); + let map_vertex = VertexBuffer::new(facade, &map_vertices).unwrap(); + + let line_vertices: Vec<_> = geom + .line_vertices + .iter() + .map(|v| MapVertex { + position: Vertex::::from(*v).to_slice() + }) + .collect(); + + let line_vertex = VertexBuffer::new(facade, &line_vertices).unwrap(); let map = IndexBuffer::new(facade, PrimitiveType::TrianglesList, geom.map_triangles).unwrap(); @@ -69,7 +80,8 @@ impl Buffer { .collect(); Buffer { - vertex, + map_vertex, + line_vertex, map, area_line, pref_line, From cb7f488261434e8fe4aa89ecb3ff69c49f2a7f5b Mon Sep 17 00:00:00 2001 From: yanorei32 Date: Wed, 24 Dec 2025 13:38:31 +0900 Subject: [PATCH 3/3] Remap AreaCode to sequential number --- asset-preprocessor/src/parse_shapefile.rs | 37 +++++++++++++++++++++-- renderer-assets/build.rs | 2 ++ renderer-assets/src/lib.rs | 11 ++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/asset-preprocessor/src/parse_shapefile.rs b/asset-preprocessor/src/parse_shapefile.rs index ed83eb1..e88ec1c 100644 --- a/asset-preprocessor/src/parse_shapefile.rs +++ b/asset-preprocessor/src/parse_shapefile.rs @@ -13,6 +13,35 @@ use renderer_types::*; use crate::math::*; +struct AreaCodeBuffer { + area_code_to_internal_code: HashMap, +} + +impl AreaCodeBuffer { + fn new() -> Self { + Self { + area_code_to_internal_code: Default::default(), + } + } + + fn insert(&mut self, area_code: u32) -> u16 { + match self.area_code_to_internal_code.get(&area_code) { + Some(index) => *index, + None => { + let index = self.area_code_to_internal_code.len(); + self.area_code_to_internal_code + .insert(area_code, index as u16); + index as u16 + } + } + } + + fn into_buffer(self) -> HashMap { + self.area_code_to_internal_code + } +} + + struct VertexBuffer { buffer: Vec, dict: HashMap, @@ -207,18 +236,20 @@ pub fn read( ) -> ( HashMap>, // area_bounding_box HashMap>, // area_centers - Vec<(f32, f32, u32)>, // map_vertex_buffer + Vec<(f32, f32, u16)>, // map_vertex_buffer Vec<(f32, f32)>, // line_vertex_buffer Vec, // map_indices Vec>, // area_lines Vec>, // pref_lines Vec<(f32, usize)>, // scale_level_map + HashMap, // area_code_to_internal_code ) { let shapefile = Shapefile::new( "../assets/shapefile/earthquake_detailed/earthquake_detailed_simplified.shp", "../assets/shapefile/earthquake_detailed/earthquake_detailed_simplified.dbf", ); let mut map_vertex_buffer = VertexBuffer::new(); + let mut area_code_buffer = AreaCodeBuffer::new(); // @Siro_256 にゃ~っ…! (ΦωΦ) @@ -235,6 +266,7 @@ pub fn read( for entry in &shapefile.entries { let area_code = entry.area_code; + let internal_code = area_code_buffer.insert(area_code); map_indices.extend( entry @@ -243,7 +275,7 @@ pub fn read( .flat_map(|ring| ring.triangulate()) .map(|p| { let p = Into::<(Of32, Of32)>::into(p); - map_vertex_buffer.insert((p.0, p.1, area_code)) as u32 + map_vertex_buffer.insert((p.0, p.1, internal_code)) as u32 }), ); } @@ -343,6 +375,7 @@ pub fn read( area_lines, pref_lines, scale_level_map, + area_code_buffer.into_buffer(), ) } } diff --git a/renderer-assets/build.rs b/renderer-assets/build.rs index 373826b..b452bb7 100644 --- a/renderer-assets/build.rs +++ b/renderer-assets/build.rs @@ -31,6 +31,7 @@ fn main() { area_lines, pref_lines, scale_level_map, + area_code_to_internal_code, ) = parse_shapefile::read(&area_code__pref_code); // @@ -66,6 +67,7 @@ fn main() { const_declaration!(MAP_VERTICES = map_vertices), const_declaration!(LINE_VERTICES = line_vertices), const_declaration!(MAP_TRIANGLES = indices), + const_declaration!(AREA_CODE_TO_INTERNAL_CODE = area_code_to_internal_code), const_declaration!(AREA_LINES = area_lines), const_declaration!(PREF_LINES = pref_lines), const_declaration!(SCALE_LEVEL_MAP = scale_level_map), diff --git a/renderer-assets/src/lib.rs b/renderer-assets/src/lib.rs index 02a3a6b..ce8266b 100644 --- a/renderer-assets/src/lib.rs +++ b/renderer-assets/src/lib.rs @@ -8,7 +8,7 @@ use renderer_types::*; pub struct QueryInterface; pub struct Geometries { - pub map_vertices: &'static [(f32, f32, u32)], + pub map_vertices: &'static [(f32, f32, u16)], pub map_triangles: &'static [u32], pub line_vertices: &'static [(f32, f32)], pub area_lines: &'static [&'static [u32]], @@ -37,6 +37,15 @@ impl QueryInterface { indices: LAKE_INDICES, } } + + pub fn area_code_to_internal_code(area_code: codes::Area) -> Option { + AREA_CODE_TO_INTERNAL_CODE.get(&area_code).copied() + } + + pub fn area_code_count() -> usize { + AREA_CODE_TO_INTERNAL_CODE.len() + } + pub fn query_bounding_box_by_area(area_code: codes::Area) -> Option> { Some(BoundingBox::from_tuple::( AREAS.get(&area_code)?.1,