///
/// Computes the per vertex normals and updates the normals of the mesh.
/// It will override the current normals if they already exist.
///
Computes the per vertex normals and updates the normals of the mesh.
It will override the current normals if they already exist.
Computes the per vertex normals and updates the normals of the mesh . It will override the current normals if they already exist .
pub fn compute_normals(&mut self) {
        let mut normals = vec![Vec3::new(0.0, 0.0, 0.0); self.positions.len()];
        self.for_each_triangle(|i0, i1, i2| {
            let normal = match self.positions {
                Positions::F32(ref positions) => {
                    let p0 = positions[i0];
                    let p1 = positions[i1];
                    let p2 = positions[i2];
                    (p1 - p0).cross(p2 - p0)
                }
                Positions::F64(ref positions) => {
                    let p0 = positions[i0];
                    let p1 = positions[i1];
                    let p2 = positions[i2];
                    let n = (p1 - p0).cross(p2 - p0);
                    Vec3::new(n.x as f32, n.y as f32, n.z as f32)
                }
            };
            normals[i0] += normal;
            normals[i1] += normal;
            normals[i2] += normal;
        });
        for n in normals.iter_mut() {
            *n = n.normalize();
        }
        self.normals = Some(normals);
    }
pub fn compute_normals ( & mut self ) { let mut normals = vec ! [ Vec3 new ( 0.0 0.0 0.0 ) self positions len ( ) ] ; self . for_each_triangle ( | i0 , i1 , i2 | { let normal = match self . positions { Positions :: F32 ( ref positions ) => { let p0 = positions [ i0 ] ; let p1 = positions [ i1 ] ; let p2 = positions [ i2 ] ; ( p1 - p0 ) . cross ( p2 - p0 ) } Positions :: F64 ( ref positions ) => { let p0 = positions [ i0 ] ; let p1 = positions [ i1 ] ; let p2 = positions [ i2 ] ; let n = ( p1 - p0 ) . cross ( p2 - p0 ) ; Vec3 :: new ( n . x as f32 , n . y as f32 , n . z as f32 ) } } ; normals [ i0 ] += normal ; normals [ i1 ] += normal ; normals [ i2 ] += normal ; } ) ; for n in normals . iter_mut ( ) { * n = n . normalize ( ) ; } self . normals = Some ( normals ) ; }
Computes the per vertex normals and updates the normals of the mesh.
Computes the per vertex normals and updates the normals of the mesh .
&mut self