Skip to content

Commit

Permalink
fix normals computation for gltf (#13396)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf committed May 18, 2024
1 parent 450a920 commit a55e0e3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a55e0e3

Please sign in to comment.