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
@ -981,7 +981,7 @@ impl RenderAsset for Mesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct MikktspaceGeometryHelper<'a> {
|
struct MikktspaceGeometryHelper<'a> {
|
||||||
indices: &'a Indices,
|
indices: Option<&'a Indices>,
|
||||||
positions: &'a Vec<[f32; 3]>,
|
positions: &'a Vec<[f32; 3]>,
|
||||||
normals: &'a Vec<[f32; 3]>,
|
normals: &'a Vec<[f32; 3]>,
|
||||||
uvs: &'a Vec<[f32; 2]>,
|
uvs: &'a Vec<[f32; 2]>,
|
||||||
@ -993,15 +993,19 @@ impl MikktspaceGeometryHelper<'_> {
|
|||||||
let index_index = face * 3 + vert;
|
let index_index = face * 3 + vert;
|
||||||
|
|
||||||
match self.indices {
|
match self.indices {
|
||||||
Indices::U16(indices) => indices[index_index] as usize,
|
Some(Indices::U16(indices)) => indices[index_index] as usize,
|
||||||
Indices::U32(indices) => indices[index_index] as usize,
|
Some(Indices::U32(indices)) => indices[index_index] as usize,
|
||||||
|
None => index_index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl bevy_mikktspace::Geometry for MikktspaceGeometryHelper<'_> {
|
impl bevy_mikktspace::Geometry for MikktspaceGeometryHelper<'_> {
|
||||||
fn num_faces(&self) -> usize {
|
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 {
|
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 len = positions.len();
|
||||||
let tangents = vec![[0., 0., 0., 0.]; len];
|
let tangents = vec![[0., 0., 0., 0.]; len];
|
||||||
let mut mikktspace_mesh = MikktspaceGeometryHelper {
|
let mut mikktspace_mesh = MikktspaceGeometryHelper {
|
||||||
indices,
|
indices: mesh.indices(),
|
||||||
positions,
|
positions,
|
||||||
normals,
|
normals,
|
||||||
uvs,
|
uvs,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user