pub fn calculate_flat_normals(&mut self) {
        let mut provoking_set = BTreeSet::new();

        for is in self.indices.chunks_exact_mut(3) {
            let p0 = Vector3::from(self.vertices[is[0] as usize].position);
            let p1 = Vector3::from(self.vertices[is[1] as usize].position);
            let p2 = Vector3::from(self.vertices[is[2] as usize].position);
            let a = p1 - p0;
            let b = p2 - p0;
            let normal = a.cross(&b).normalize();

            if provoking_set.insert(is[2]) {
                self.vertices[is[2] as usize].normal = normal.into();
            } else if provoking_set.insert(is[1]) {
                self.vertices[is[1] as usize].normal = normal.into();
                is.rotate_right(1);
            } else if provoking_set.insert(is[0]) {
                self.vertices[is[0] as usize].normal = normal.into();
                is.rotate_left(1);
            } else {
                // relabel is[2]
                let old_is2 = is[2];
                let mut i2 = self.vertices[old_is2 as usize];
                i2.normal = normal.into();
                let new_is2 = self.vertices.len() as u16;
                is[2] = new_is2;
                self.vertices.push(i2);
            }
        }
    }
/// Calculate normals ONLY for "provoking" vertices of this triangle mesh. This is useful for
/// flat shading for wireframes and such, but not for more general "smooth" normals. It works
/// with the wireframe vertex/fragment shaders, which expect flat normal data.
///
/// This method may invalidate some vertex indices, as different triangles cannot share the same
/// provoking vertex. If a repeated provoking vertex is found, we first try rotating the
/// triangle to get a different provoking vertex; if all provoking vertices are taken, we must
/// duplicate a vertex, use it to carry the new normal, and then replace the original index we
/// duplicated in the triangle. As such, this method may add vertices to the mesh, but it will
/// add at most ~1/3 the number of vertices the mesh started with, in the very worst of worst
/// cases.
Calculate normals ONLY for "provoking" vertices of this triangle mesh. This is useful for
flat shading for wireframes and such, but not for more general "smooth" normals. It works
with the wireframe vertex/fragment shaders, which expect flat normal data.

This method may invalidate some vertex indices, as different triangles cannot share the same
provoking vertex. If a repeated provoking vertex is found, we first try rotating the
triangle to get a different provoking vertex; if all provoking vertices are taken, we must
duplicate a vertex, use it to carry the new normal, and then replace the original index we
duplicated in the triangle. As such, this method may add vertices to the mesh, but it will
add at most ~1/3 the number of vertices the mesh started with, in the very worst of worst
cases.
Calculate normals ONLY for " provoking " vertices of this triangle mesh . This is useful for flat shading for wireframes and such but not for more general " smooth " normals . It works with the wireframe vertex / fragment shaders which expect flat normal data . This method may invalidate some vertex indices as different triangles cannot share the same provoking vertex . If a repeated provoking vertex is found we first try rotating the triangle to get a different provoking vertex ; if all provoking vertices are taken we must duplicate a vertex use it to carry the new normal and then replace the original index we duplicated in the triangle . As such this method may add vertices to the mesh but it will add at most ~1 / 3 the number of vertices the mesh started with in the very worst of worst cases .
pub fn calculate_flat_normals(&mut self) {
        let mut provoking_set = BTreeSet::new();
        for is in self.indices.chunks_exact_mut(3) {
            let p0 = Vector3::from(self.vertices[is[0] as usize].position);
            let p1 = Vector3::from(self.vertices[is[1] as usize].position);
            let p2 = Vector3::from(self.vertices[is[2] as usize].position);
            let a = p1 - p0;
            let b = p2 - p0;
            let normal = a.cross(&b).normalize();
            if provoking_set.insert(is[2]) {
                self.vertices[is[2] as usize].normal = normal.into();
            } else if provoking_set.insert(is[1]) {
                self.vertices[is[1] as usize].normal = normal.into();
                is.rotate_right(1);
            } else if provoking_set.insert(is[0]) {
                self.vertices[is[0] as usize].normal = normal.into();
                is.rotate_left(1);
            } else {
                // relabel is[2]
                let old_is2 = is[2];
                let mut i2 = self.vertices[old_is2 as usize];
                i2.normal = normal.into();
                let new_is2 = self.vertices.len() as u16;
                is[2] = new_is2;
                self.vertices.push(i2);
            }
        }
    }
pub fn calculate_flat_normals ( & mut self ) { let mut provoking_set = BTreeSet :: new ( ) ; for is in self . indices . chunks_exact_mut ( 3 ) { let p0 = Vector3 :: from ( self . vertices [ is [ 0 ] as usize ] . position ) ; let p1 = Vector3 :: from ( self . vertices [ is [ 1 ] as usize ] . position ) ; let p2 = Vector3 :: from ( self . vertices [ is [ 2 ] as usize ] . position ) ; let a = p1 - p0 ; let b = p2 - p0 ; let normal = a . cross ( & b ) . normalize ( ) ; if provoking_set . insert ( is [ 2 ] ) { self . vertices [ is [ 2 ] as usize ] . normal = normal . into ( ) ; } else if provoking_set . insert ( is [ 1 ] ) { self . vertices [ is [ 1 ] as usize ] . normal = normal . into ( ) ; is . rotate_right ( 1 ) ; } else if provoking_set . insert ( is [ 0 ] ) { self . vertices [ is [ 0 ] as usize ] . normal = normal . into ( ) ; is . rotate_left ( 1 ) ; } else { // relabel is[2] let old_is2 = is [ 2 ] ; let mut i2 = self . vertices [ old_is2 as usize ] ; i2 . normal = normal . into ( ) ; let new_is2 = self . vertices . len ( ) as u16 ; is [ 2 ] = new_is2 ; self . vertices . push ( i2 ) ; } } }
Calculate normals ONLY for "provoking" vertices of this triangle mesh.
Calculate normals ONLY for " provoking " vertices of this triangle mesh .
&mut self
&mut self