From 886f92470cd2febcbed128e39af7013163efd249 Mon Sep 17 00:00:00 2001
From: zomseffen <steffen@tom.bi>
Date: Wed, 22 Jan 2025 10:10:47 +0100
Subject: [PATCH] volume creation improvement 1

---
 src/primitives/cube.rs    |   3 +-
 src/scene/empty_volume.rs | 597 +++++++++++++++++++-------------------
 src/scene/mod.rs          |   8 +-
 src/scene/oct_tree.rs     | 100 ++++++-
 4 files changed, 402 insertions(+), 306 deletions(-)

diff --git a/src/primitives/cube.rs b/src/primitives/cube.rs
index fd27a1e..38d5f8f 100644
--- a/src/primitives/cube.rs
+++ b/src/primitives/cube.rs
@@ -8,7 +8,8 @@ use crate::primitives::drawable::Drawable;
 pub struct Cube{
     pub pos: vertex::Vec3,
     pub color: vertex::Vec3,
-    pub tex_coord: vertex::Vec2
+    pub tex_coord: vertex::Vec2,
+    pub transparent: bool,
 }
 
 const cube_size: f32 = 0.48;
diff --git a/src/scene/empty_volume.rs b/src/scene/empty_volume.rs
index 6176f33..a97e19c 100644
--- a/src/scene/empty_volume.rs
+++ b/src/scene/empty_volume.rs
@@ -61,314 +61,309 @@ impl EmptyVolume {
             for y_index in 0..tree.size {
                 for z_index in 0..tree.size {
                     // check if there is a block at that position
-                    let query_result = tree.get_element(x_index, y_index, z_index);
+                    let query_result = tree.test_element(x_index, y_index, z_index);
                     
-                    match query_result {
-                        Some(cube) => {
-                            //if so do nothing
-                        },
-                        None => {
-                            //if not check that it is not already inside of a volume
-                            let mut contained = false;
-                            for volume in &volumes {
-                                if volume.borrow().contains(&Vector3{x: x_index, y: y_index, z: z_index}) {
-                                    contained = true;
-                                    break;
-                                }
+                    if !query_result.0 {
+                        //if not check that it is not already inside of a volume
+                        let mut contained = false;
+                        for volume in &volumes {
+                            if volume.borrow().contains(&Vector3{x: x_index, y: y_index, z: z_index}) {
+                                contained = true;
+                                break;
                             }
-                            if contained {
-                                // abort if it is already covered
-                                continue;
+                        }
+                        if contained {
+                            // abort if it is already covered
+                            continue;
+                        }
+                        println!("new starting pos: {}, {}, {}", x_index, y_index, z_index);
+                        println!("start growing volume x");
+                        // MARK: Start new Volume
+                        let mut x_size = 0;
+                        let mut grow = true;
+                        while grow {
+                            grow = tree.get_element(x_index + x_size + 1, y_index, z_index).is_none() && neighbors.get_element(x_index + x_size + 1, y_index, z_index).is_none();
+                            grow &= (x_index + x_size + 1) < tree.size;
+                            if grow {
+                                x_size += 1;
                             }
-                            println!("new starting pos: {}, {}, {}", x_index, y_index, z_index);
-                            println!("start growing volume x");
-                            // MARK: Start new Volume
-                            let mut x_size = 0;
-                            let mut grow = true;
-                            while grow {
-                                grow = tree.get_element(x_index + x_size + 1, y_index, z_index).is_none() && neighbors.get_element(x_index + x_size + 1, y_index, z_index).is_none();
-                                grow &= (x_index + x_size + 1) < tree.size;
-                                if grow {
-                                    x_size += 1;
-                                }
-                            }
-                            println!("start growing volume y");
-                            let mut y_size = 0;
-                            grow = true;
-                            while grow {
-                                grow &= (y_index + y_size + 1) < tree.size;
-                                if grow { 
-                                    for x in 0..x_size {
-                                        grow &= tree.get_element(x_index + x, y_index + y_size + 1, z_index).is_none() &&
-                                        neighbors.get_element(x_index + x, y_index + y_size + 1, z_index).is_none();
-                                        
-                                        if !grow {
-                                            break;
-                                        }
-                                    } 
-                                }
-                                
-                                if grow {
-                                    y_size += 1;
-                                }
-                            }
-                            println!("start growing volume z");
-                            let mut z_size = 0;
-                            grow = true;
-                            while grow {
-                                grow &= (z_index + z_size + 1) < tree.size;
-                                if grow {
-                                    for x in 0..x_size {
-                                        for y in 0..y_size {
-                                            grow &= tree.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none() &&
-                                                neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
-                                            if !grow {
-                                                break;
-                                            }
-                                        }
-                                        if !grow {
-                                            break;
-                                        }
+                        }
+                        println!("start growing volume y");
+                        let mut y_size = 0;
+                        grow = true;
+                        while grow {
+                            grow &= (y_index + y_size + 1) < tree.size;
+                            if grow { 
+                                for x in 0..x_size {
+                                    grow &= tree.get_element(x_index + x, y_index + y_size + 1, z_index).is_none() &&
+                                    neighbors.get_element(x_index + x, y_index + y_size + 1, z_index).is_none();
+                                    
+                                    if !grow {
+                                        break;
                                     }
-                                }
-                                if grow {
-                                    z_size += 1;
-                                }
-                            }
-                            println!("final size: {}, {}, {}", x_size+1, y_size+1, z_size+1);
-                            // create new empty volume
-                            let new_volume = EmptyVolume {
-                                memory_start: 0,
-                                size_x: x_size + 1,
-                                size_y: y_size + 1,
-                                size_z: z_size + 1,
-                                position: Vector3{x: x_index, y: y_index, z: z_index},
-                                color_left: vec![],
-                                color_right: vec![],
-                                color_top: vec![],
-                                color_bottom: vec![],
-                                color_back: vec![],
-                                color_front: vec![],
-                                roughness_left: vec![],
-                                roughness_right: vec![],
-                                roughness_top: vec![],
-                                roughness_bottom: vec![],
-                                roughness_back: vec![],
-                                roughness_front: vec![],
-                                neighbor_left: vec![],
-                                neighbor_right: vec![],
-                                neighbor_top: vec![],
-                                neighbor_bottom: vec![],
-                                neighbor_back: vec![],
-                                neighbor_front: vec![],
-                            };
-                            println!("adding neighbor references");
-                            // MARK: fill in info in the neighbor octtree
-                            let reference = Rc::new(RefCell::new(new_volume));
-                            for x in 0..x_size+1 {
-                                for y in 0..y_size+1 {
-                                    for z in 0..z_size+1 {
-                                        neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z);
-                                        // fill only the edges
-                                        /*if x == 0 || x == x_size || y == 0 || y == y_size || z==0 || z == z_size {
-                                            neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z)
-                                        }*/
-                                    }   
-                                }
-                            }
-                            println!("add the border information for color and roughness");
-                            let x_min_pos;
-                            if reference.borrow().position.x == 0 {
-                                // will result in an empty color and roughness map.
-                                x_min_pos = 0;
-                            }
-                            else {
-                                x_min_pos = reference.borrow().position.x -1;
-                            }
-                            let y_min_pos;
-                            if reference.borrow().position.y == 0 {
-                                // will result in an empty color and roughness map.
-                                y_min_pos = 0;
-                            }
-                            else {
-                                y_min_pos = reference.borrow().position.y -1;
-                            }
-                            let z_min_pos;
-                            if reference.borrow().position.z == 0 {
-                                // will result in an empty color and roughness map.
-                                z_min_pos = 0;
-                            }
-                            else {
-                                z_min_pos = reference.borrow().position.z -1;
-                            }
-                            let x_max_pos = reference.borrow().position.x + reference.borrow().size_x;
-                            let y_max_pos = reference.borrow().position.y + reference.borrow().size_y;
-                            let z_max_pos = reference.borrow().position.z + reference.borrow().size_z;
-                            // MARK: bottom face of the volume
-                            let mut bottom_colors = vec![];
-                            let mut bottom_roughness = vec![];
-                            let mut bottom_elements_num = 0;
-                            for x in 0..x_size+1 {
-                                for y in 0..y_size+1 {
-                                    if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
-                                        bottom_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        bottom_colors.push(u8_color);
-                                        bottom_roughness.push(128);
-                                    }
-                                    else {
-                                        bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        bottom_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if bottom_elements_num > 0 {
-                                reference.borrow_mut().color_bottom = bottom_colors;
-                                reference.borrow_mut().roughness_bottom = bottom_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_bottom= vec![];
-                                reference.borrow_mut().roughness_bottom= vec![];
-                            }
-                            // MARK: top face of the volume
-                            let mut top_colors = vec![];
-                            let mut top_roughness = vec![];
-                            let mut top_elements_num = 0;
-                            for x in 0..x_size+1 {
-                                for y in 0..y_size+1 {
-                                    if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_max_pos) {
-                                        top_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        top_colors.push(u8_color);
-                                        top_roughness.push(128);
-                                    }
-                                    else {
-                                        top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        top_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if top_elements_num > 0 {
-                                reference.borrow_mut().color_top = top_colors;
-                                reference.borrow_mut().roughness_top = top_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_top= vec![];
-                                reference.borrow_mut().roughness_top= vec![];
-                            }
-
-                            // MARK: back face of the volume
-                            let mut back_colors = vec![];
-                            let mut back_roughness = vec![];
-                            let mut back_elements_num = 0;
-                            for x in 0..x_size+1 {
-                                for z in 0..z_size+1 {
-                                    if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_max_pos, reference.borrow().position.z + z) {
-                                        back_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        back_colors.push(u8_color);
-                                        back_roughness.push(128);
-                                    }
-                                    else {
-                                        back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        back_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if back_elements_num > 0 {
-                                reference.borrow_mut().color_back = back_colors;
-                                reference.borrow_mut().roughness_back = back_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_back= vec![];
-                                reference.borrow_mut().roughness_back= vec![];
-                            }
-
-                            // MARK: front face of the volume
-                            let mut front_colors = vec![];
-                            let mut front_roughness = vec![];
-                            let mut front_elements_num = 0;
-                            for x in 0..x_size+1 {
-                                for z in 0..z_size+1 {
-                                    if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
-                                        front_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        front_colors.push(u8_color);
-                                        front_roughness.push(128);
-                                    }
-                                    else {
-                                        front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        front_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if front_elements_num > 0 {
-                                reference.borrow_mut().color_front = front_colors;
-                                reference.borrow_mut().roughness_front = front_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_front= vec![];
-                                reference.borrow_mut().roughness_front= vec![];
-                            }
-
-                            // MARK: left face of the volume
-                            let mut left_colors = vec![];
-                            let mut left_roughness = vec![];
-                            let mut left_elements_num = 0;
-                            for y in 0..y_size+1 {
-                                for z in 0..z_size+1 {
-                                    if let Some(c) = tree.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
-                                        left_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        left_colors.push(u8_color);
-                                        left_roughness.push(128);
-                                    }
-                                    else {
-                                        left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        left_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if left_elements_num > 0 {
-                                reference.borrow_mut().color_left = left_colors;
-                                reference.borrow_mut().roughness_left = left_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_left= vec![];
-                                reference.borrow_mut().roughness_left= vec![];
-                            }
-
-                            // MARK: right face of the volume
-                            let mut right_colors = vec![];
-                            let mut right_roughness = vec![];
-                            let mut right_elements_num = 0;
-                            for y in 0..y_size+1 {
-                                for z in 0..z_size+1 {
-                                    if let Some(c) = tree.get_element(x_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
-                                        right_elements_num += 1;
-                                        let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
-                                        right_colors.push(u8_color);
-                                        right_roughness.push(128);
-                                    }
-                                    else {
-                                        right_colors.push(Vector3 { x: 0, y: 0, z: 0 });
-                                        right_roughness.push(0);
-                                    }
-                                }
-                            }
-                            if right_elements_num > 0 {
-                                reference.borrow_mut().color_right = right_colors;
-                                reference.borrow_mut().roughness_right = right_roughness;
-                            }
-                            else {
-                                reference.borrow_mut().color_right= vec![];
-                                reference.borrow_mut().roughness_right= vec![];
+                                } 
                             }
                             
-                            println!("new volume done");
-                            //push to the list
-                            volumes.push(reference);
+                            if grow {
+                                y_size += 1;
+                            }
                         }
+                        println!("start growing volume z");
+                        let mut z_size = 0;
+                        grow = true;
+                        while grow {
+                            grow &= (z_index + z_size + 1) < tree.size;
+                            if grow {
+                                for x in 0..x_size {
+                                    for y in 0..y_size {
+                                        grow &= tree.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none() &&
+                                            neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
+                                        if !grow {
+                                            break;
+                                        }
+                                    }
+                                    if !grow {
+                                        break;
+                                    }
+                                }
+                            }
+                            if grow {
+                                z_size += 1;
+                            }
+                        }
+                        println!("final size: {}, {}, {}", x_size+1, y_size+1, z_size+1);
+                        // create new empty volume
+                        let new_volume = EmptyVolume {
+                            memory_start: 0,
+                            size_x: x_size + 1,
+                            size_y: y_size + 1,
+                            size_z: z_size + 1,
+                            position: Vector3{x: x_index, y: y_index, z: z_index},
+                            color_left: vec![],
+                            color_right: vec![],
+                            color_top: vec![],
+                            color_bottom: vec![],
+                            color_back: vec![],
+                            color_front: vec![],
+                            roughness_left: vec![],
+                            roughness_right: vec![],
+                            roughness_top: vec![],
+                            roughness_bottom: vec![],
+                            roughness_back: vec![],
+                            roughness_front: vec![],
+                            neighbor_left: vec![],
+                            neighbor_right: vec![],
+                            neighbor_top: vec![],
+                            neighbor_bottom: vec![],
+                            neighbor_back: vec![],
+                            neighbor_front: vec![],
+                        };
+                        println!("adding neighbor references");
+                        // MARK: fill in info in the neighbor octtree
+                        let reference = Rc::new(RefCell::new(new_volume));
+                        for x in 0..x_size+1 {
+                            for y in 0..y_size+1 {
+                                for z in 0..z_size+1 {
+                                    neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z);
+                                    // fill only the edges
+                                    /*if x == 0 || x == x_size || y == 0 || y == y_size || z==0 || z == z_size {
+                                        neighbors.set_element(reference.clone(), reference.borrow().position.x + x, reference.borrow().position.y + y, reference.borrow().position.z + z)
+                                    }*/
+                                }   
+                            }
+                        }
+                        println!("add the border information for color and roughness");
+                        let x_min_pos;
+                        if reference.borrow().position.x == 0 {
+                            // will result in an empty color and roughness map.
+                            x_min_pos = 0;
+                        }
+                        else {
+                            x_min_pos = reference.borrow().position.x -1;
+                        }
+                        let y_min_pos;
+                        if reference.borrow().position.y == 0 {
+                            // will result in an empty color and roughness map.
+                            y_min_pos = 0;
+                        }
+                        else {
+                            y_min_pos = reference.borrow().position.y -1;
+                        }
+                        let z_min_pos;
+                        if reference.borrow().position.z == 0 {
+                            // will result in an empty color and roughness map.
+                            z_min_pos = 0;
+                        }
+                        else {
+                            z_min_pos = reference.borrow().position.z -1;
+                        }
+                        let x_max_pos = reference.borrow().position.x + reference.borrow().size_x;
+                        let y_max_pos = reference.borrow().position.y + reference.borrow().size_y;
+                        let z_max_pos = reference.borrow().position.z + reference.borrow().size_z;
+                        // MARK: bottom face of the volume
+                        let mut bottom_colors = vec![];
+                        let mut bottom_roughness = vec![];
+                        let mut bottom_elements_num = 0;
+                        for x in 0..x_size+1 {
+                            for y in 0..y_size+1 {
+                                if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_min_pos) {
+                                    bottom_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    bottom_colors.push(u8_color);
+                                    bottom_roughness.push(128);
+                                }
+                                else {
+                                    bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    bottom_roughness.push(0);
+                                }
+                            }
+                        }
+                        if bottom_elements_num > 0 {
+                            reference.borrow_mut().color_bottom = bottom_colors;
+                            reference.borrow_mut().roughness_bottom = bottom_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_bottom= vec![];
+                            reference.borrow_mut().roughness_bottom= vec![];
+                        }
+                        // MARK: top face of the volume
+                        let mut top_colors = vec![];
+                        let mut top_roughness = vec![];
+                        let mut top_elements_num = 0;
+                        for x in 0..x_size+1 {
+                            for y in 0..y_size+1 {
+                                if let Some(c) = tree.get_element(reference.borrow().position.x + x, reference.borrow().position.y + y, z_max_pos) {
+                                    top_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    top_colors.push(u8_color);
+                                    top_roughness.push(128);
+                                }
+                                else {
+                                    top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    top_roughness.push(0);
+                                }
+                            }
+                        }
+                        if top_elements_num > 0 {
+                            reference.borrow_mut().color_top = top_colors;
+                            reference.borrow_mut().roughness_top = top_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_top= vec![];
+                            reference.borrow_mut().roughness_top= vec![];
+                        }
+
+                        // MARK: back face of the volume
+                        let mut back_colors = vec![];
+                        let mut back_roughness = vec![];
+                        let mut back_elements_num = 0;
+                        for x in 0..x_size+1 {
+                            for z in 0..z_size+1 {
+                                if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_max_pos, reference.borrow().position.z + z) {
+                                    back_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    back_colors.push(u8_color);
+                                    back_roughness.push(128);
+                                }
+                                else {
+                                    back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    back_roughness.push(0);
+                                }
+                            }
+                        }
+                        if back_elements_num > 0 {
+                            reference.borrow_mut().color_back = back_colors;
+                            reference.borrow_mut().roughness_back = back_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_back= vec![];
+                            reference.borrow_mut().roughness_back= vec![];
+                        }
+
+                        // MARK: front face of the volume
+                        let mut front_colors = vec![];
+                        let mut front_roughness = vec![];
+                        let mut front_elements_num = 0;
+                        for x in 0..x_size+1 {
+                            for z in 0..z_size+1 {
+                                if let Some(c) = tree.get_element(reference.borrow().position.x + x, y_min_pos, reference.borrow().position.z + z) {
+                                    front_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    front_colors.push(u8_color);
+                                    front_roughness.push(128);
+                                }
+                                else {
+                                    front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    front_roughness.push(0);
+                                }
+                            }
+                        }
+                        if front_elements_num > 0 {
+                            reference.borrow_mut().color_front = front_colors;
+                            reference.borrow_mut().roughness_front = front_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_front= vec![];
+                            reference.borrow_mut().roughness_front= vec![];
+                        }
+
+                        // MARK: left face of the volume
+                        let mut left_colors = vec![];
+                        let mut left_roughness = vec![];
+                        let mut left_elements_num = 0;
+                        for y in 0..y_size+1 {
+                            for z in 0..z_size+1 {
+                                if let Some(c) = tree.get_element(x_min_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
+                                    left_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    left_colors.push(u8_color);
+                                    left_roughness.push(128);
+                                }
+                                else {
+                                    left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    left_roughness.push(0);
+                                }
+                            }
+                        }
+                        if left_elements_num > 0 {
+                            reference.borrow_mut().color_left = left_colors;
+                            reference.borrow_mut().roughness_left = left_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_left= vec![];
+                            reference.borrow_mut().roughness_left= vec![];
+                        }
+
+                        // MARK: right face of the volume
+                        let mut right_colors = vec![];
+                        let mut right_roughness = vec![];
+                        let mut right_elements_num = 0;
+                        for y in 0..y_size+1 {
+                            for z in 0..z_size+1 {
+                                if let Some(c) = tree.get_element(x_max_pos, reference.borrow().position.y + y, reference.borrow().position.z + z) {
+                                    right_elements_num += 1;
+                                    let u8_color = Vector3 {x: (c.color * 255.0).x.min(255.0).max(0.0) as u8, y: (c.color * 255.0).y.min(255.0).max(0.0) as u8, z: (c.color * 255.0).z.min(255.0).max(0.0) as u8};
+                                    right_colors.push(u8_color);
+                                    right_roughness.push(128);
+                                }
+                                else {
+                                    right_colors.push(Vector3 { x: 0, y: 0, z: 0 });
+                                    right_roughness.push(0);
+                                }
+                            }
+                        }
+                        if right_elements_num > 0 {
+                            reference.borrow_mut().color_right = right_colors;
+                            reference.borrow_mut().roughness_right = right_roughness;
+                        }
+                        else {
+                            reference.borrow_mut().color_right= vec![];
+                            reference.borrow_mut().roughness_right= vec![];
+                        }
+                        
+                        println!("new volume done");
+                        //push to the list
+                        volumes.push(reference);
                     }                    
                 }
             }
diff --git a/src/scene/mod.rs b/src/scene/mod.rs
index 160636a..a91b1a8 100644
--- a/src/scene/mod.rs
+++ b/src/scene/mod.rs
@@ -72,7 +72,8 @@ impl Scene {
                 let cube = Cube {
                     pos: vec3(x_index as f32, y_index as f32, 5.0),
                     color: vec3(shade, 1.0, shade),
-                    tex_coord: vec2(0.0, 0.0)
+                    tex_coord: vec2(0.0, 0.0),
+                    transparent: false,
                 };
 
                 oct_tree.set_cube(cube.clone());
@@ -83,7 +84,8 @@ impl Scene {
         let cube = Cube {
             pos: vec3(10.0, 10.0, 10.0),
             color: vec3(1.0, 1.0, 0.0),
-            tex_coord: vec2(0.0, 0.0)
+            tex_coord: vec2(0.0, 0.0),
+            transparent: true,
         };
 
         oct_tree.set_cube(cube.clone());
@@ -167,7 +169,7 @@ impl Scene {
         for light in &self.point_lights {
             volume_vec = light.insert_into_memory(volume_vec);
         }
-        println!("volume_vec print {:?}", volume_vec);
+        //println!("volume_vec print {:?}", volume_vec);
 
         self.rt_memory = volume_vec;
         data.scene_rt_memory_size = (self.rt_memory.len() * 4) as u64; // size of the needed buffer size in bytes
diff --git a/src/scene/oct_tree.rs b/src/scene/oct_tree.rs
index 7f6a3ba..53cfd70 100644
--- a/src/scene/oct_tree.rs
+++ b/src/scene/oct_tree.rs
@@ -377,6 +377,104 @@ impl<T: Clone> OctTree<T> {
             self.blocks[z * MIN_CHUNK_SIZE * MIN_CHUNK_SIZE + y * MIN_CHUNK_SIZE + x].clone()
         }
     }
+
+    pub fn test_element(&self, x: usize, y: usize, z: usize) -> (bool, usize, (usize, usize, usize)) {
+        self.test_element_internal(x, y, z, 0, 0, 0)
+    }
+
+    fn test_element_internal(&self, x: usize, y: usize, z: usize, node_start_x: usize, node_start_y: usize, node_start_z: usize) -> (bool, usize, (usize, usize, usize)) {
+        if x >= self.size || y >= self.size || z >= self.size {
+            return (false, 0, (0, 0, 0))
+        }
+
+        if self.size > MIN_CHUNK_SIZE {
+            let mid_point = self.size / 2;
+            if x >= mid_point {
+                if y >= mid_point {
+                    if z >= mid_point {
+                        match &self.child_XYZ {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x - mid_point, y - mid_point, z - mid_point, node_start_x + mid_point, node_start_y + mid_point, node_start_z + mid_point)
+                            },
+                            None => (false, mid_point, (node_start_x + mid_point, node_start_y + mid_point, node_start_z + mid_point))
+                        }
+                    }
+                    else {
+                        match &self.child_XYz {
+                            Some(child) => {
+                                child.borrow().test_element_internal( x - mid_point, y - mid_point, z, node_start_x + mid_point, node_start_y + mid_point, node_start_z)
+                            },
+                            None => (false, mid_point, (node_start_x + mid_point, node_start_y + mid_point, node_start_z))
+                        }
+                    }
+                }
+                else {
+                    if z >= mid_point {
+                        match &self.child_XyZ {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x - mid_point, y, z - mid_point, node_start_x + mid_point, node_start_y, node_start_z + mid_point)
+                            },
+                            None => (false, mid_point, (node_start_x + mid_point, node_start_y, node_start_z + mid_point))
+                        }
+                    }
+                    else {
+                        match &self.child_Xyz {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x - mid_point, y, z, node_start_x + mid_point, node_start_y, node_start_z)
+                            },
+                            None => (false, mid_point, (node_start_x + mid_point, node_start_y, node_start_z))
+                        }
+                    }
+                }
+            }
+            else {
+                if y >= mid_point {
+                    if z >= mid_point {
+                        match &self.child_xYZ {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x, y - mid_point, z - mid_point, node_start_x, node_start_y + mid_point, node_start_z + mid_point)
+                            },
+                            None => (false, mid_point, (node_start_x, node_start_y + mid_point, node_start_z + mid_point))
+                        }
+                    }
+                    else {
+                        match &self.child_xYz {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x, y - mid_point, z, node_start_x, node_start_y + mid_point, node_start_z)
+                            },
+                            None => (false, mid_point, (node_start_x, node_start_y + mid_point, node_start_z))
+                        }
+                    }
+                }
+                else {
+                    if z >= mid_point {
+                        match &self.child_xyZ {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x, y, z - mid_point, node_start_x, node_start_y, node_start_z + mid_point)
+                            },
+                            None => (false, mid_point, (node_start_x, node_start_y, node_start_z + mid_point))
+                        }
+                    }
+                    else {
+                        match &self.child_xyz {
+                            Some(child) => {
+                                child.borrow().test_element_internal(x, y, z, node_start_x, node_start_y, node_start_z)
+                            },
+                            None => (false, mid_point, (node_start_x , node_start_y, node_start_z))
+                        }
+                    }
+                }
+            }
+        }
+        else {
+            if let Some(_) = self.blocks[z * MIN_CHUNK_SIZE * MIN_CHUNK_SIZE + y * MIN_CHUNK_SIZE + x] {
+                (true, 1, (x, y, z))
+            }
+            else {
+                (false, 1, (x, y, z))
+            }
+        }
+    }
 }
 
 pub struct OctTreeIter<'a> {
@@ -503,7 +601,7 @@ mod test {
     #[test]
     fn test_oct_tree(){
         let mut test_tree: OctTree<Cube> = OctTree::create(512).unwrap();
-        let test_cube = Cube{color: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, pos: Vector3 { x: 5.0, y: 2.0, z: 10.0 }, tex_coord: Vector2{x: 0.0, y: 0.0}};
+        let test_cube = Cube{color: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, pos: Vector3 { x: 5.0, y: 2.0, z: 10.0 }, tex_coord: Vector2{x: 0.0, y: 0.0}, transparent: false};
 
         test_tree.set_cube(test_cube.clone());