This commit is contained in:
Dongho Kim
2025-12-16 00:42:33 +09:00
parent 45807e3a90
commit 8edb92b25d
6 changed files with 210 additions and 55 deletions

View File

@@ -33,6 +33,8 @@ use tiles::{fetch_cached, get_visible_tiles, get_parent_tile};
use labels::update_labels;
use pipelines::{
Vertex,
ColoredVertex,
create_simple_pipeline,
create_building_pipeline,
create_water_pipeline,
create_water_line_pipeline,
@@ -420,7 +422,7 @@ pub async fn run() {
let mut landuse_residential_vertex_data: Vec<Vertex> = Vec::new();
let mut landuse_sand_vertex_data: Vec<Vertex> = Vec::new();
let mut water_vertex_data: Vec<Vertex> = Vec::new();
let mut railway_vertex_data: Vec<Vertex> = Vec::new();
let mut railway_vertex_data: Vec<ColoredVertex> = Vec::new();
let mut water_line_vertex_data: Vec<Vertex> = Vec::new();
// Process ways (roads)
@@ -518,17 +520,23 @@ pub async fn run() {
}
}
// Process railways
// Process railways with colors
if let Some(railway_list) = state_guard.railways.get(&tile) {
for railway in railway_list {
// Parse color from tags (format: "#RRGGBB" or "#RGB")
let color = railway.tags.get("colour")
.or(railway.tags.get("color"))
.map(|c| parse_hex_color(c))
.unwrap_or([0.0, 0.0, 0.0]); // Default: no color (shader uses grey)
// Parse all points first
let mut rail_points: Vec<Vertex> = Vec::new();
let mut rail_points: Vec<ColoredVertex> = Vec::new();
for chunk in railway.points.chunks(8) {
if chunk.len() < 8 { break; }
let lat = f32::from_le_bytes(chunk[0..4].try_into().unwrap_or([0u8; 4]));
let lon = f32::from_le_bytes(chunk[4..8].try_into().unwrap_or([0u8; 4]));
let (x, y) = project(lat as f64, lon as f64);
rail_points.push(Vertex { position: [x, y] });
rail_points.push(ColoredVertex { position: [x, y], color });
}
// For LineList: push pairs of vertices for each segment
@@ -897,3 +905,25 @@ pub async fn run() {
}
}).unwrap();
}
/// Parse a hex color string (e.g., "#FF0000" or "#F00") into RGB floats [0.0-1.0]
fn parse_hex_color(hex: &str) -> [f32; 3] {
let hex = hex.trim_start_matches('#');
if hex.len() == 6 {
// #RRGGBB format
let r = u8::from_str_radix(&hex[0..2], 16).unwrap_or(0) as f32 / 255.0;
let g = u8::from_str_radix(&hex[2..4], 16).unwrap_or(0) as f32 / 255.0;
let b = u8::from_str_radix(&hex[4..6], 16).unwrap_or(0) as f32 / 255.0;
[r, g, b]
} else if hex.len() == 3 {
// #RGB format (shorthand)
let r = u8::from_str_radix(&hex[0..1], 16).unwrap_or(0) as f32 / 15.0;
let g = u8::from_str_radix(&hex[1..2], 16).unwrap_or(0) as f32 / 15.0;
let b = u8::from_str_radix(&hex[2..3], 16).unwrap_or(0) as f32 / 15.0;
[r, g, b]
} else {
// Invalid format, return black (will trigger grey fallback in shader)
[0.0, 0.0, 0.0]
}
}