mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
generate indices for Mikktspace (#8862)
# Objective mikktspace tangent generation requires mesh indices, and currently fails when they are not present. we can just generate them instead. ## Solution generate the indices.
This commit is contained in:
parent
c61faf35b8
commit
9d23f828f6
1 changed files with 9 additions and 8 deletions
|
@ -981,7 +981,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]>,
|
||||
|
@ -993,15 +993,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 {
|
||||
|
@ -1080,14 +1084,11 @@ fn generate_tangents_for_mesh(mesh: &Mesh) -> Result<Vec<[f32; 4]>, 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,
|
||||
|
|
Loading…
Reference in a new issue