Johann Woelper 5 anni fa
parent
commit
b8fb45c590
4 ha cambiato i file con 323 aggiunte e 53 eliminazioni
  1. 3 0
      .gitignore
  2. BIN
      landscape.blend
  3. 258 34
      out.json
  4. 62 19
      src/main.rs

+ 3 - 0
.gitignore

@@ -1,3 +1,6 @@
 /target
 **/*.rs.bk
 .history/
+*.blend1
+*.zip
+landscape_lib

BIN
landscape.blend


+ 258 - 34
out.json

@@ -1,34 +1,258 @@
-{
-    "-88,-72,0": "road-end-low",
-    "-88,-64,0": "road-tjunction-low",
-    "-80,-64,0": "road-straight-low",
-    "-96,-72,0": "building-office-small",
-    "-72,-72,0": "road-corner-low",
-    "-72,-64,0": "road-crossing-low",
-    "-80,-56,0": "grass",
-    "-64,-64,0": "road-straight-low",
-    "-56,-64,0": "road-straight-low",
-    "-48,-64,0": "road-straight-low",
-    "-72,-56,0": "road-straight-low-rot",
-    "-72,-48,0": "road-straight-low-rot",
-    "-80,-48,0": "grass",
-    "-64,-56,0": "grass",
-    "-64,-48,0": "grass",
-    "-56,-56,0": "grass",
-    "-56,-48,0": "grass",
-    "-48,-56,0": "grass",
-    "-48,-48,0": "grass",
-    "-64,-72,0": "grass",
-    "-48,-72,0": "grass",
-    "-88,-56,0": "road-straight-low-rot",
-    "-88,-48,0": "road-straight-low-rot",
-    "-96,-64,0": "road-straight-low",
-    "-56,-72,0": "building-office-small",
-    "-96,-56,0": "grass",
-    "-96,-48,0": "grass",
-    "-104,-64,0": "road-end-low",
-    "-80,-72,0": "road-straight-low",
-    "-104,-56,0": "grass",
-    "-104,-48,0": "grass",
-    "-104,-72,0": "grass"
-}
+[
+    {
+        "name": "road-end-low",
+        "pos": [
+            -88.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-tjunction-low",
+        "pos": [
+            -88.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -80.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "building-office-small",
+        "pos": [
+            -96.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-corner-low",
+        "pos": [
+            -72.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-crossing-low",
+        "pos": [
+            -72.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -80.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -64.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -56.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -48.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low-rot",
+        "pos": [
+            -72.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low-rot",
+        "pos": [
+            -72.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -80.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -64.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -64.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -56.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -56.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -48.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -48.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -64.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -48.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low-rot",
+        "pos": [
+            -88.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low-rot",
+        "pos": [
+            -88.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -96.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "building-office-small",
+        "pos": [
+            -56.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -96.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -96.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-end-low",
+        "pos": [
+            -104.0,
+            -64.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -80.0,
+            -72.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -104.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -104.0,
+            -48.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -104.0,
+            -72.0,
+            0.0
+        ]
+    }
+]

+ 62 - 19
src/main.rs

@@ -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();