|
|
@@ -96,14 +96,14 @@ impl<'a, 'b> Add<&'b V3> for &'a V3 {
|
|
|
// }
|
|
|
|
|
|
|
|
|
-#[derive(Clone, Debug)]
|
|
|
-struct Voxel {
|
|
|
- id: String,
|
|
|
- // adjacency: HashMap<&'static str, u16>,
|
|
|
- adjacency: HashMap<V3, Vec<String>>,
|
|
|
- // offsets: [V3; 6]
|
|
|
+// #[derive(Clone, Debug)]
|
|
|
+// struct Voxel {
|
|
|
+// id: String,
|
|
|
+// // adjacency: HashMap<&'static str, u16>,
|
|
|
+// adjacency: HashMap<V3, Vec<String>>,
|
|
|
+// // offsets: [V3; 6]
|
|
|
|
|
|
-}
|
|
|
+// }
|
|
|
|
|
|
/// A graphics tile as ex- or imported from a 3d program
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
@@ -149,110 +149,88 @@ fn guess_gridsize(vol: &HashMap<V3, String>) -> i32{
|
|
|
|
|
|
}
|
|
|
|
|
|
-fn train_volume(vol: &HashMap<V3, Voxel>) -> HashMap<String, HashMap<V3, Vec<String>>> {
|
|
|
+fn train_volume(vol: &HashMap<V3, String>) -> HashMap<String, HashMap<V3, Vec<String>>> {
|
|
|
|
|
|
- // let mut trainedd: HashMap<Vector3<i32>, Vec<String>> = HashMap::new();
|
|
|
- // Tile name offset Vec of tile names
|
|
|
let mut trained: HashMap<String, HashMap<V3, Vec<String>>> = HashMap::new();
|
|
|
|
|
|
- for (pos, voxel) in vol {
|
|
|
+ for (pos, tilename) in vol {
|
|
|
// lookup neighbors
|
|
|
|
|
|
- // let mut neighbors: HashMap<V3, Vec<String>> = HashMap::new();
|
|
|
-
|
|
|
- let tile = trained.entry(voxel.id.clone()).or_insert(
|
|
|
+ let tile = trained.entry(tilename.clone()).or_insert(
|
|
|
HashMap::new()
|
|
|
);
|
|
|
|
|
|
-
|
|
|
- // dbg!(&voxel.id);
|
|
|
- // dbg!(&pos);
|
|
|
- // dbg!(&pos.neighbors()[0]);
|
|
|
- // dbg!(&pos.offsets()[0]);
|
|
|
-
|
|
|
for p_o in pos.offsets().iter() {
|
|
|
let p_n = p_o + pos;
|
|
|
if let Some(neighbor) = vol.get(&p_n) {
|
|
|
if let Some(neighbor_tile) = tile.get_mut(&p_o) {
|
|
|
- neighbor_tile.push(neighbor.id.clone());
|
|
|
+ neighbor_tile.push(neighbor.clone());
|
|
|
} else {
|
|
|
- tile.insert(p_o.clone(), vec![neighbor.id.clone()]);
|
|
|
+ tile.insert(p_o.clone(), vec![neighbor.clone()]);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
- // *tile;
|
|
|
}
|
|
|
- // dbg!(&trained);
|
|
|
trained
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
fn load_export(path: &'static str) -> HashMap<V3, String> {
|
|
|
let reader = BufReader::new(File::open(path).unwrap());
|
|
|
let loaded_tiles: Vec<GfxTile> = serde_json::from_reader(reader).unwrap();
|
|
|
- // let vec_tiles: HashMap<Vector3<i32>, String> =
|
|
|
-
|
|
|
loaded_tiles
|
|
|
.iter()
|
|
|
.map(|x| {
|
|
|
(V3::new(x.pos[0] as i32, x.pos[1] as i32, x.pos[2] as i32), x.name.clone())
|
|
|
})
|
|
|
.collect()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // dbg!(&loaded_tiles);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// fn get_adjacent(volume: HashMap<Vector3<i32>, Voxel>, Vector3<i32>) {
|
|
|
+fn wfc_solver(training_data: HashMap<String, HashMap<V3, Vec<String>>>) -> HashMap<V3, String> {
|
|
|
+ let mut new_grid: HashMap<V3, String> = HashMap::new();
|
|
|
+ // init start conditions
|
|
|
+ new_grid.insert(V3::new(0, 0, 0), String::from("grass"));
|
|
|
|
|
|
|
|
|
-// }
|
|
|
+ loop {
|
|
|
+ if new_grid.len() > 50 {break;}
|
|
|
+ }
|
|
|
|
|
|
+ new_grid
|
|
|
+}
|
|
|
|
|
|
fn main() {
|
|
|
|
|
|
simplelog::SimpleLogger::init(LevelFilter::Info, Config::default());
|
|
|
|
|
|
|
|
|
- let mut vol: HashMap<V3, Voxel> = HashMap::new();
|
|
|
-
|
|
|
+ let mut import_volume: HashMap<V3, String> = HashMap::new();
|
|
|
let imported_tiles = load_export("out.json");
|
|
|
let gridsize = guess_gridsize(&imported_tiles);
|
|
|
- // dbg!(&gridsize);
|
|
|
info!("Detected grid size: {}", gridsize);
|
|
|
let imported_tiles = unitized_grid(&imported_tiles, gridsize);
|
|
|
info!("Tiles imported: {}", imported_tiles.len());
|
|
|
|
|
|
|
|
|
for (pos, tile) in imported_tiles {
|
|
|
- vol.insert(pos, Voxel {id: tile, adjacency: HashMap::new()});
|
|
|
+ import_volume.insert(pos, tile);
|
|
|
}
|
|
|
|
|
|
- let trained_volume = train_volume(&vol);
|
|
|
- info!("Training done: {} tiles", trained_volume.len());
|
|
|
+ let training_data = train_volume(&import_volume);
|
|
|
+ info!("Training done: {} tiles", training_data.len());
|
|
|
|
|
|
- // for (tilename, adjacency_map) in trained_volume {
|
|
|
-
|
|
|
+ // for (tilename, adjacency_map) in training_data {
|
|
|
// println!("\n{}", tilename);
|
|
|
-
|
|
|
// for (pos, fitting_tiles) in adjacency_map{
|
|
|
// println!("{:?}{:?}", pos, fitting_tiles);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
+ let new_grid: HashMap<V3, String> = HashMap::new();
|
|
|
+
|
|
|
// dbg!(&vol);
|
|
|
// let mut adj_map: HashMap<String, Adjacency> = HashMap::new();
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
-#[test]
|
|
|
-fn create_vol() {
|
|
|
-
|
|
|
-}
|