diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 7d91788e7d27a..0d69926b9a177 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -887,7 +887,7 @@ impl RenderAsset for Mesh { } struct MikktspaceGeometryHelper<'a> { - indices: &'a Indices, + indices: Option<&'a Indices>, positions: &'a Vec<[f32; 3]>, normals: &'a Vec<[f32; 3]>, uvs: &'a Vec<[f32; 2]>, @@ -899,15 +899,19 @@ impl MikktspaceGeometryHelper<'_> { let index_index = face * 3 + vert; match self.indices { - Indices::U16(indices) => indices[index_index] as usize, - Indices::U32(indices) => indices[index_index] as usize, + Some(Indices::U16(indices)) => indices[index_index] as usize, + Some(Indices::U32(indices)) => indices[index_index] as usize, + None => index_index, } } } impl bevy_mikktspace::Geometry for MikktspaceGeometryHelper<'_> { fn num_faces(&self) -> usize { - self.indices.len() / 3 + self.indices + .map(Indices::len) + .unwrap_or_else(|| self.positions.len()) + / 3 } fn num_vertices_of_face(&self, _: usize) -> usize { @@ -986,14 +990,11 @@ fn generate_tangents_for_mesh(mesh: &Mesh) -> Result, GenerateTang )) } }; - let indices = mesh - .indices() - .ok_or(GenerateTangentsError::MissingIndices)?; let len = positions.len(); let tangents = vec![[0., 0., 0., 0.]; len]; let mut mikktspace_mesh = MikktspaceGeometryHelper { - indices, + indices: mesh.indices(), positions, normals, uvs,