|
@@ -12,36 +12,74 @@ use nalgebra::Vector3;
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
struct Voxel {
|
|
|
id: String,
|
|
|
- adjacency: HashMap<&'static str, u16>,
|
|
|
+ // adjacency: HashMap<&'static str, u16>,
|
|
|
+ adjacency: HashMap<Vector3<i32>, Vec<String>>
|
|
|
}
|
|
|
|
|
|
+#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
+struct GfxTile {
|
|
|
+ name: String,
|
|
|
+ pos: Vec<f32>,
|
|
|
+}
|
|
|
|
|
|
|
|
|
+fn unitized_grid(vol: &HashMap<Vector3<i32>, String>, divisor: i32) -> HashMap<Vector3<i32>, String> {
|
|
|
+ // vol
|
|
|
+ vol.iter().map(|(k,v)| (k.clone()/divisor,v.clone())).collect()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+fn guess_gridsize(vol: &HashMap<Vector3<i32>, String>) -> i32{
|
|
|
+ let mut x_positions: Vec<i32> = vol.iter().map(|(k,v)| k.x).collect();
|
|
|
+ x_positions.sort();
|
|
|
+ x_positions.dedup();
|
|
|
+ let mut dist_count: HashMap<i32, i32> = HashMap::new();
|
|
|
+ let mut last: Option<i32> = None;
|
|
|
+ for px in x_positions {
|
|
|
+ if let Some(l) = last {
|
|
|
+ let delta = px.abs() - l;
|
|
|
+ let c = dist_count.entry(delta.abs()).or_insert(1);
|
|
|
+ *c += 1;
|
|
|
+ }
|
|
|
+ last = Some(px.abs());
|
|
|
+ }
|
|
|
+
|
|
|
+ let mut grid = 0;
|
|
|
+ let mut maxcount = 0;
|
|
|
+ for (size, count) in dist_count {
|
|
|
+ if count > maxcount {
|
|
|
+ grid = size;
|
|
|
+ maxcount = count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // dbg!(&grid);
|
|
|
+ grid
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+fn train_volume(vol: &HashMap<Vector3<i32>, Voxel>) {
|
|
|
+ let mut trained: HashMap<Vector3<i32>, Voxel> = HashMap::new();
|
|
|
+ for voxel in vol {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-// #[derive(Clone, Debug, Default)]
|
|
|
-// struct Adjacency {
|
|
|
-// p_x: HashMap<&'static str, u16>,
|
|
|
-// n_x: HashMap<&'static str, u16>,
|
|
|
-
|
|
|
-// p_y: HashMap<&'static str, u16>,
|
|
|
-// n_y: HashMap<&'static str, u16>,
|
|
|
-
|
|
|
-// p_z: HashMap<&'static str, u16>,
|
|
|
-// n_z: HashMap<&'static str, u16>,
|
|
|
-// }
|
|
|
|
|
|
fn load_export(path: &'static str) -> HashMap<Vector3<i32>, String> {
|
|
|
let reader = BufReader::new(File::open(path).unwrap());
|
|
|
- let loaded_tiles: HashMap<String, String> = serde_json::from_reader(reader).unwrap();
|
|
|
+ let loaded_tiles: Vec<GfxTile> = serde_json::from_reader(reader).unwrap();
|
|
|
// let vec_tiles: HashMap<Vector3<i32>, String> =
|
|
|
+
|
|
|
loaded_tiles
|
|
|
.iter()
|
|
|
- .map(|(k,v)| {
|
|
|
- let p: Vec<i32> = k.split(",").map(|x| x.parse().unwrap_or(0)).collect();
|
|
|
- (Vector3::new(p[0],p[1],p[2]), v.clone())
|
|
|
+ .map(|x| {
|
|
|
+ (Vector3::new(x.pos[0] as i32, x.pos[1] as i32, x.pos[2] as i32), x.name.clone())
|
|
|
})
|
|
|
.collect()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// dbg!(&loaded_tiles);
|
|
|
|
|
|
}
|
|
@@ -56,15 +94,20 @@ fn load_export(path: &'static str) -> HashMap<Vector3<i32>, String> {
|
|
|
fn main() {
|
|
|
|
|
|
let mut vol: HashMap<Vector3<i32>, Voxel> = HashMap::new();
|
|
|
- vol.insert(Vector3::new(1,0,0), Voxel {id: "border_left".to_string(), ..Default::default()});
|
|
|
- vol.insert(Vector3::new(1,0,1), Voxel {id: "straight".to_string(), ..Default::default()});
|
|
|
+
|
|
|
+ let imported_tiles = load_export("out.json");
|
|
|
+ let grid = guess_gridsize(&imported_tiles);
|
|
|
+ let imported_tiles = unitized_grid(&imported_tiles, grid);
|
|
|
|
|
|
|
|
|
- for (pos, tile) in load_export("out.json") {
|
|
|
+ for (pos, tile) in imported_tiles {
|
|
|
// dbg!(&pos, &tile);
|
|
|
vol.insert(pos, Voxel {id: tile, ..Default::default()});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
dbg!(&vol);
|
|
|
// let mut adj_map: HashMap<String, Adjacency> = HashMap::new();
|
|
|
|