/// Build a mesh, adding whatever components weren't provided.
///
/// If normals weren't provided, they will be calculated. If mesh
/// is right handed, will be converted to left handed.
///
/// All others will be filled with defaults.
Build a mesh, adding whatever components weren't provided.
If normals weren't provided, they will be calculated. If mesh
is right handed, will be converted to left handed.

All others will be filled with defaults.
Build a mesh adding whatever components weren ' t provided . If normals weren ' t provided they will be calculated . If mesh is right handed will be converted to left handed . All others will be filled with defaults .
pub fn build(self) -> Result<Mesh, MeshValidationError> {
        let length = self.vertex_count;
        debug_assert_ne!(length, 0, "Length should be guarded by validation");
        let has_normals = self.vertex_normals.is_some();
        let has_tangents = self.vertex_tangents.is_some();
        let has_uvs = self.vertex_uv0.is_some();
        let mut mesh = Mesh {
            vertex_positions: self.vertex_positions,
            vertex_normals: self.vertex_normals.unwrap_or_else(|| vec![Vec3::ZERO; length]),
            vertex_tangents: self.vertex_tangents.unwrap_or_else(|| vec![Vec3::ZERO; length]),
            vertex_uv0: self.vertex_uv0.unwrap_or_else(|| vec![Vec2::ZERO; length]),
            vertex_uv1: self.vertex_uv1.unwrap_or_else(|| vec![Vec2::ZERO; length]),
            vertex_colors: self.vertex_colors.unwrap_or_else(|| vec![[255; 4]; length]),
            vertex_material_indices: self.vertex_material_indices.unwrap_or_else(|| vec![0; length]),
            indices: self.indices.unwrap_or_else(|| (0..length as u32).collect()),
            // SAFETY: Before we do _anything_ with this mesh, we will validate it. If validation is off, the user has unsafely validated that this is safe to construct.
            validation: unsafe { MeshValidationToken::new() },
        };
        if !self.without_validation {
            mesh.validate()?;
        }
        // We need to flip winding order first, so the normals will be facing the right direction.
        if self.right_handed {
            mesh.flip_winding_order();
        }
        if !has_normals {
            mesh.calculate_normals(true);
        }
        // Don't need to bother with tangents if there are no meaningful UVs
        if !has_tangents && has_uvs {
            mesh.calculate_tangents(true);
        }
        Ok(mesh)
    }
pub fn build ( self ) -> Result < Mesh , MeshValidationError > { let length = self . vertex_count ; debug_assert_ne ! ( length 0 " " ) ; let has_normals = self . vertex_normals . is_some ( ) ; let has_tangents = self . vertex_tangents . is_some ( ) ; let has_uvs = self . vertex_uv0 . is_some ( ) ; let mut mesh = Mesh { vertex_positions : self . vertex_positions , vertex_normals : self . vertex_normals . unwrap_or_else ( | | vec ! [ Vec3 ZERO length ] ) , vertex_tangents : self . vertex_tangents . unwrap_or_else ( | | vec ! [ Vec3 ZERO length ] ) , vertex_uv0 : self . vertex_uv0 . unwrap_or_else ( | | vec ! [ Vec2 ZERO length ] ) , vertex_uv1 : self . vertex_uv1 . unwrap_or_else ( | | vec ! [ Vec2 ZERO length ] ) , vertex_colors : self . vertex_colors . unwrap_or_else ( | | vec ! [ [ 255 4 ] length ] ) , vertex_material_indices : self . vertex_material_indices . unwrap_or_else ( | | vec ! [ 0 length ] ) , indices : self . indices . unwrap_or_else ( | | ( 0 .. length as u32 ) . collect ( ) ) , // SAFETY: Before we do _anything_ with this mesh, we will validate it. If validation is off, the user has unsafely validated that this is safe to construct. validation : unsafe { MeshValidationToken :: new ( ) } , } ; if ! self . without_validation { mesh . validate ( ) ? ; } // We need to flip winding order first, so the normals will be facing the right direction. if self . right_handed { mesh . flip_winding_order ( ) ; } if ! has_normals { mesh . calculate_normals ( true ) ; } // Don't need to bother with tangents if there are no meaningful UVs if ! has_tangents && has_uvs { mesh . calculate_tangents ( true ) ; } Ok ( mesh ) }
Build a mesh, adding whatever components weren't provided.
Build a mesh adding whatever components weren ' t provided .
self