// generates vertices from the labelled vertices
generates vertices from the labelled vertices
generates vertices from the labelled vertices
fn generate_vertices(&mut self, tri_table: &TriangulationTable) {
        // creates tables for vertices and indices
        let mut vertices_table = Vec::<f32>::new();
        let mut indices_table = Vec::<u32>::new();
        // generates a full offset for the position of the cubes
        let full_offset = Vector3::new(
            (self.offset.x as f32 * self.chunk_bounds as f32 * self.spacing_per_vertex) - (self.offset.x as f32 * self.spacing_per_vertex),
            (self.offset.y as f32 * self.chunk_bounds as f32 * self.spacing_per_vertex) - (self.offset.y as f32 * self.spacing_per_vertex),
            (self.offset.z as f32 * self.chunk_bounds as f32 * self.spacing_per_vertex) - (self.offset.z as f32 * self.spacing_per_vertex)
        );
        // temporary indexing thing 
        let mut index: u32 = 0;
        // gets the cubes marching
        for x in 0..(CHUNK_BOUNDS - 1) {
            for y in 0..(CHUNK_BOUNDS - 1) {
                for z in 0..(CHUNK_BOUNDS - 1) {
                    // creates a bitwise representation of the cube that's 
                    // currently being marched on
                    let mut cube_config: u8 = 0;
                    // manual for now, replace later
                    cube_config |= (self.grid[[x, y, z]] as u8) << 0;
                    cube_config |= (self.grid[[x + 1, y, z]] as u8) << 1;
                    cube_config |= (self.grid[[x + 1, y, z + 1]] as u8) << 2;
                    cube_config |= (self.grid[[x, y, z + 1]] as u8) << 3;
                    cube_config |= (self.grid[[x, y + 1, z]] as u8) << 4;
                    cube_config |= (self.grid[[x + 1, y + 1, z]] as u8) << 5;
                    cube_config |= (self.grid[[x + 1, y + 1, z + 1]] as u8) << 6;
                    cube_config |= (self.grid[[x, y + 1, z + 1]] as u8) << 7;
                    // if the cube offset is not 0 or 255 (empty or full), proceed
                    if cube_config != 0 && cube_config != 255 {
                        // gets the cube configuration vertices from the triangulation table
                        let cube_vertices = tri_table.table.get(&(cube_config as u16)).unwrap();
                        // loops over the cube vertices
                        for vert in cube_vertices.iter() {
                            // based on the indices, gets the corner configurations associated
                            // with the vert
                            let corner_a = *tri_table.corner_index_a_from_edge.get(*vert as usize).unwrap();
                            let corner_b = *tri_table.corner_index_b_from_edge.get(*vert as usize).unwrap();
                            // gets the sampled values at the corners that are being assessed
                            let corner_a_weight = self.grid_weights[[
                                x + corner_a.x as usize,
                                y + corner_a.y as usize,
                                z + corner_a.z as usize
                            ]];
                            let corner_b_weight = self.grid_weights[[
                                x + corner_b.x as usize,
                                y + corner_b.y as usize,
                                z + corner_b.z as usize
                            ]];
                            // interpolates between the grid weights
                            let interp_value = (self.isovalue - corner_a_weight) / (corner_b_weight - corner_a_weight);
                            // gets an interpolated value between the two corners
                            let interp_corners = corner_a + (interp_value * (corner_b - corner_a));
                            // calculates the vertex point from a number of different factors
                            let vertex_point = Vector3::new(
                                ((x as f32 + interp_corners.x) * self.spacing_per_vertex) + full_offset.x,
                                ((y as f32 + interp_corners.y) * self.spacing_per_vertex) + full_offset.y,
                                ((z as f32 + interp_corners.z) * self.spacing_per_vertex) + full_offset.z
                            );
                            // adds the vertex point to the vertices
                            vertices_table.push(vertex_point.x);
                            vertices_table.push(vertex_point.y);
                            vertices_table.push(vertex_point.z);
                            // pushes the indices, increments
                            indices_table.push(index);
                            indices_table.push(index + 1);
                            indices_table.push(index + 2);
                            index = index + 3;
                        }
                    }
                }
            }
        }
        // sets the vertices table
        self.vertices = vertices_table;
        self.indices = indices_table;
    }
fn generate_vertices ( & mut self , tri_table : & TriangulationTable ) { // creates tables for vertices and indices let mut vertices_table = Vec :: < f32 > :: new ( ) ; let mut indices_table = Vec :: < u32 > :: new ( ) ; // generates a full offset for the position of the cubes let full_offset = Vector3 :: new ( ( self . offset . x as f32 * self . chunk_bounds as f32 * self . spacing_per_vertex ) - ( self . offset . x as f32 * self . spacing_per_vertex ) , ( self . offset . y as f32 * self . chunk_bounds as f32 * self . spacing_per_vertex ) - ( self . offset . y as f32 * self . spacing_per_vertex ) , ( self . offset . z as f32 * self . chunk_bounds as f32 * self . spacing_per_vertex ) - ( self . offset . z as f32 * self . spacing_per_vertex ) ) ; // temporary indexing thing  let mut index : u32 = 0 ; // gets the cubes marching for x in 0 .. ( CHUNK_BOUNDS - 1 ) { for y in 0 .. ( CHUNK_BOUNDS - 1 ) { for z in 0 .. ( CHUNK_BOUNDS - 1 ) { // creates a bitwise representation of the cube that's  // currently being marched on let mut cube_config : u8 = 0 ; // manual for now, replace later cube_config |= ( self . grid [ [ x , y , z ] ] as u8 ) << 0 ; cube_config |= ( self . grid [ [ x + 1 , y , z ] ] as u8 ) << 1 ; cube_config |= ( self . grid [ [ x + 1 , y , z + 1 ] ] as u8 ) << 2 ; cube_config |= ( self . grid [ [ x , y , z + 1 ] ] as u8 ) << 3 ; cube_config |= ( self . grid [ [ x , y + 1 , z ] ] as u8 ) << 4 ; cube_config |= ( self . grid [ [ x + 1 , y + 1 , z ] ] as u8 ) << 5 ; cube_config |= ( self . grid [ [ x + 1 , y + 1 , z + 1 ] ] as u8 ) << 6 ; cube_config |= ( self . grid [ [ x , y + 1 , z + 1 ] ] as u8 ) << 7 ; // if the cube offset is not 0 or 255 (empty or full), proceed if cube_config != 0 && cube_config != 255 { // gets the cube configuration vertices from the triangulation table let cube_vertices = tri_table . table . get ( & ( cube_config as u16 ) ) . unwrap ( ) ; // loops over the cube vertices for vert in cube_vertices . iter ( ) { // based on the indices, gets the corner configurations associated // with the vert let corner_a = * tri_table . corner_index_a_from_edge . get ( * vert as usize ) . unwrap ( ) ; let corner_b = * tri_table . corner_index_b_from_edge . get ( * vert as usize ) . unwrap ( ) ; // gets the sampled values at the corners that are being assessed let corner_a_weight = self . grid_weights [ [ x + corner_a . x as usize , y + corner_a . y as usize , z + corner_a . z as usize ] ] ; let corner_b_weight = self . grid_weights [ [ x + corner_b . x as usize , y + corner_b . y as usize , z + corner_b . z as usize ] ] ; // interpolates between the grid weights let interp_value = ( self . isovalue - corner_a_weight ) / ( corner_b_weight - corner_a_weight ) ; // gets an interpolated value between the two corners let interp_corners = corner_a + ( interp_value * ( corner_b - corner_a ) ) ; // calculates the vertex point from a number of different factors let vertex_point = Vector3 :: new ( ( ( x as f32 + interp_corners . x ) * self . spacing_per_vertex ) + full_offset . x , ( ( y as f32 + interp_corners . y ) * self . spacing_per_vertex ) + full_offset . y , ( ( z as f32 + interp_corners . z ) * self . spacing_per_vertex ) + full_offset . z ) ; // adds the vertex point to the vertices vertices_table . push ( vertex_point . x ) ; vertices_table . push ( vertex_point . y ) ; vertices_table . push ( vertex_point . z ) ; // pushes the indices, increments indices_table . push ( index ) ; indices_table . push ( index + 1 ) ; indices_table . push ( index + 2 ) ; index = index + 3 ; } } } } } // sets the vertices table self . vertices = vertices_table ; self . indices = indices_table ; }
generates vertices from the labelled vertices
generates vertices from the labelled vertices
&mut self
tri_table
&TriangulationTable