diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 43 | ||||
-rw-r--r-- | src/spatial/octtree.rs | 3 | ||||
-rw-r--r-- | viewer/index.html | 12 | ||||
-rw-r--r-- | viewer/main.ts | 19 |
6 files changed, 60 insertions, 21 deletions
@@ -1 +1,3 @@ /target +/viewer/bundle.js* + @@ -6,9 +6,9 @@ edition = "2024" [dependencies] anyhow = "1.0.97" env_logger = "0.11.7" +glam = "0.30.1" indicatif = { version = "0.17.11", features = ["rayon"] } log = "0.4.27" osm-pbf-reader = "0.1.1" rayon = "1.10.0" -glam = "0.30.1" weareshared = { path = "../wearechat/shared" } diff --git a/src/main.rs b/src/main.rs index 7f13114..1ce78ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ pub mod spatial; use anyhow::Result; -use glam::DVec3; +use glam::{Affine3A, DAffine3, DVec3, Vec3}; use indicatif::ProgressIterator; use log::{debug, info}; use osm_pbf_reader::{Blobs, data::primitives::Primitive}; @@ -9,6 +9,7 @@ use rayon::iter::{ParallelBridge, ParallelIterator}; use spatial::{SpatialTree, octtree::Octtree}; use std::{collections::BTreeMap, env::args, f64::consts::PI, fs::File, io::BufWriter}; use weareshared::{ + graphics::GraphicsPart, helper::AABB, packets::Resource, resources::{Prefab, RespackEntry, SpatialIndex}, @@ -21,6 +22,7 @@ fn main() -> Result<()> { let inpath = args().nth(1).unwrap(); let outpath = args().nth(2).unwrap(); + info!("Indexing node positions..."); let node_positions = Blobs::from_path(&inpath)? .progress_count(1_500) .par_bridge() @@ -49,7 +51,7 @@ fn main() -> Result<()> { || BTreeMap::new(), |mut a, b| { if !a.is_empty() && !b.is_empty() { - debug!("merge positions {} + {}", a.len(), b.len()); + debug!("merge {} + {}", a.len(), b.len()); } a.extend(b); a @@ -64,11 +66,15 @@ fn main() -> Result<()> { info!("Done, depth={}", tree.depth()); let store = ResourceStore::new_memory(); + + info!("Exporting resources..."); let (_, root) = export_level(&tree, &store)?; let entry = Some(store.set(&RespackEntry { c_spatial_index: vec![root], ..Default::default() })?); + info!("Done, N={}", store.count()?); + let output = BufWriter::new(File::create(outpath)?); save_full_respack(output, &store, entry)?; @@ -88,7 +94,17 @@ fn export_level(node: &Octtree, store: &ResourceStore) -> Result<(AABB, Resource let prefab = if node.elems.is_empty() { None } else { + let local_origin = node.center; + let mut g = GraphicsPart::default(); + + use weareshared::graphics::GraphicsCommand::*; + g.push(StrokeWidth(0.001)); + g.push(Stroke(5)); + g.push(Point(Vec3::ZERO)); + Some(store.set(&Prefab { + transform: Some(DAffine3::from_translation(local_origin)), + graphics: vec![(Affine3A::IDENTITY, store.set(&g)?)], ..Default::default() })?) }; @@ -109,23 +125,12 @@ fn export_level(node: &Octtree, store: &ResourceStore) -> Result<(AABB, Resource type NodeID = u64; fn map_nodeid(id: i64) -> u64 { + // fn xorshift(mut x: u64) -> u64 { + // x ^= x << 13; + // x ^= x >> 7; + // x ^= x << 17; + // x + // } // xorshift(xorshift(xorshift(id as u64))) id as u64 } -fn xorshift(mut x: u64) -> u64 { - x ^= x << 13; - x ^= x >> 7; - x ^= x << 17; - x -} - -enum Elem { - Node { pos: DVec3 }, -} -impl Elem { - pub fn center(&self) -> DVec3 { - match self { - Elem::Node { pos } => *pos, - } - } -} diff --git a/src/spatial/octtree.rs b/src/spatial/octtree.rs index f8919f5..e86b471 100644 --- a/src/spatial/octtree.rs +++ b/src/spatial/octtree.rs @@ -19,6 +19,7 @@ impl Octtree { } } } +const MAX_CHILDREN: usize = 1024; impl SpatialTree for Octtree { fn insert(&mut self, pos: DVec3, id: NodeID) { if let Some(c) = &mut self.children { @@ -28,7 +29,7 @@ impl SpatialTree for Octtree { c[x][y][z].insert(pos, id); } else { self.elems.push((pos, id)); - if self.elems.len() > 64 { + if self.elems.len() > MAX_CHILDREN { self.children = Some(Box::new([-1., 1.].map(|x| { [-1., 1.].map(|y| { [-1., 1.].map(|z| Octtree { diff --git a/viewer/index.html b/viewer/index.html new file mode 100644 index 0000000..4713ed3 --- /dev/null +++ b/viewer/index.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>The Map</title> + </head> + <body> + <script src="./bundle.js"></script> + <noscript>Map viewer required JavaScript support.</noscript> + </body> +</html> diff --git a/viewer/main.ts b/viewer/main.ts new file mode 100644 index 0000000..4320b68 --- /dev/null +++ b/viewer/main.ts @@ -0,0 +1,19 @@ +/// <reference lib="dom" /> + +const canvas = document.createElement("canvas") +canvas.style.position = "absolute" +canvas.style.top = "0px" +canvas.style.left = "0px" +canvas.style.width = "100vw" +canvas.style.height = "100vh" +document.body.append(canvas) +const ctx = canvas.getContext("2d")! + +function draw() { + ctx.fillStyle = "black" + ctx.fillRect(0, 0, canvas.width, canvas.height) +} + +canvas.addEventListener("resize", () => draw()) +draw() + |