diff --git a/src/scene/generators.rs b/src/scene/generators.rs index 71dffba..55fd6c7 100644 --- a/src/scene/generators.rs +++ b/src/scene/generators.rs @@ -111,9 +111,9 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<()> let index = scene.sized_vertices.len(); cube.draw(&data.topology, index, scene); - let tree_ref_one = Rc::new(RefCell::new(oct_tree1)); - let tree_ref_two = Rc::new(RefCell::new(oct_tree2)); - scene.oct_trees = vec![vec![vec![tree_ref_one.clone(), tree_ref_two.clone()]]]; + let tree_ref_one = Rc::new(RefCell::new(oct_tree1.clone())); + let tree_ref_two = Rc::new(RefCell::new(oct_tree2.clone())); + scene.oct_trees = vec![vec![vec![tree_ref_one.clone(), tree_ref_two.clone()], vec![tree_ref_two.clone(), tree_ref_two.clone()]], vec![vec![tree_ref_one.clone(), tree_ref_two.clone()], vec![tree_ref_two.clone(), tree_ref_two.clone()]]]; Ok(()) } \ No newline at end of file diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 5ae9501..b2e933e 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -71,13 +71,15 @@ impl Scene { let mut neighbor_trees: Vec<Vec<Vec<Rc<OctTree<Rc<RefCell<EmptyVolume>>>>>>> = vec![]; - let mut x_index = 0; - let mut y_index = 0; + + let mut z_index = 0; for oct_tree_plane_xy in &self.oct_trees { neighbor_trees.push(vec![]); + let mut y_index = 0; for oct_tree_line_y in oct_tree_plane_xy { neighbor_trees[z_index].push(vec![]); + let mut x_index = 0; for oct_tree in oct_tree_line_y { let mut new_volumes: Vec<Rc<RefCell<EmptyVolume>>>; let new_neighbors; @@ -92,18 +94,26 @@ impl Scene { } z_index += 1; } - let mut x_index = 0; - let mut y_index = 0; + let mut z_index = 0; for oct_tree_plane_xy in &self.oct_trees { + let mut y_index = 0; for oct_tree_line_x in oct_tree_plane_xy { + let mut x_index = 0; for oct_tree in oct_tree_line_x { if oct_tree_line_x.len() > x_index + 1 { EmptyVolume::combine_results(oct_tree, &neighbor_trees[z_index][y_index][x_index], &oct_tree_line_x[x_index + 1], &neighbor_trees[z_index][y_index][x_index + 1], vertex::Facing::Right); EmptyVolume::combine_results(&oct_tree_line_x[x_index + 1], &neighbor_trees[z_index][y_index][x_index + 1], oct_tree, &neighbor_trees[z_index][y_index][x_index], vertex::Facing::Left); } - + if oct_tree_plane_xy.len() > y_index + 1 { + EmptyVolume::combine_results(oct_tree, &neighbor_trees[z_index][y_index][x_index], &oct_tree_plane_xy[y_index + 1][x_index], &neighbor_trees[z_index][y_index + 1][x_index], vertex::Facing::Back); + EmptyVolume::combine_results(&oct_tree_plane_xy[y_index + 1][x_index], &neighbor_trees[z_index][y_index + 1][x_index], oct_tree, &neighbor_trees[z_index][y_index][x_index], vertex::Facing::Front); + } + if self.oct_trees.len() > z_index + 1 { + EmptyVolume::combine_results(oct_tree, &neighbor_trees[z_index][y_index][x_index], &self.oct_trees[z_index + 1][y_index][x_index], &neighbor_trees[z_index + 1][y_index][x_index], vertex::Facing::Top); + EmptyVolume::combine_results(&self.oct_trees[z_index + 1][y_index][x_index], &neighbor_trees[z_index + 1][y_index][x_index], oct_tree, &neighbor_trees[z_index][y_index][x_index], vertex::Facing::Bottom); + } x_index += 1; } y_index += 1;