summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs43
1 files changed, 24 insertions, 19 deletions
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,
- }
- }
-}