fix normals computation for gltf (#13396)

# Objective

- some gltf files are broken since #13333 

```
thread 'IO Task Pool (2)' panicked at crates/bevy_render/src/mesh/mesh/mod.rs:581:9:
`compute_flat_normals` can't work on indexed geometry. Consider calling either `Mesh::compute_smooth_normals` or `Mesh::duplicate_vertices` followed by `Mesh::compute_flat_normals`.
```

- test with example `custom_gltf_vertex_attribute` or
`gltf_skinned_mesh`


## Solution

- Call the wrapper function for normals that will either call
`compute_flat_normals` or `compute_smooth_normals` as appropriate

## Testing

- Ran the two examples mentioned above
This commit is contained in:
François Mockers 2024-05-18 14:07:27 +02:00 committed by GitHub
parent 450a9202d0
commit a55e0e31e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -502,7 +502,17 @@ async fn load_gltf<'a, 'b, 'c>(
bevy_utils::tracing::debug!(
"Automatically calculating missing vertex normals for geometry."
);
let vertex_count_before = mesh.count_vertices();
mesh.duplicate_vertices();
mesh.compute_flat_normals();
let vertex_count_after = mesh.count_vertices();
if vertex_count_before != vertex_count_after {
bevy_utils::tracing::debug!("Missing vertex normals in indexed geometry, computing them as flat. Vertex count increased from {} to {}", vertex_count_before, vertex_count_after);
} else {
bevy_utils::tracing::debug!(
"Missing vertex normals in indexed geometry, computing them as flat."
);
}
}
if let Some(vertex_attribute) = reader