Unnecessary division in compute_smooth_normals (#16039)

# Objective

- Less code
- Simpler code

## Solution

- Remove unnecessary division: `normalize` already does that

## Testing

- Test added in #16038
This commit is contained in:
Stepan Koltsov 2024-10-20 19:55:08 +01:00 committed by GitHub
parent 2e2d669406
commit 472bbaae26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -690,7 +690,6 @@ impl Mesh {
.expect("`Mesh::ATTRIBUTE_POSITION` vertex attributes should be of type `float3`");
let mut normals = vec![Vec3::ZERO; positions.len()];
let mut adjacency_counts = vec![0_usize; positions.len()];
self.indices()
.unwrap()
@ -702,17 +701,13 @@ impl Mesh {
let normal = Vec3::from(face_normal(positions[a], positions[b], positions[c]));
[a, b, c].iter().for_each(|pos| {
normals[*pos] += normal;
adjacency_counts[*pos] += 1;
});
});
// average (smooth) normals for shared vertices...
// TODO: support different methods of weighting the average
for i in 0..normals.len() {
let count = adjacency_counts[i];
if count > 0 {
normals[i] = (normals[i] / (count as f32)).normalize();
}
for normal in &mut normals {
*normal = normal.try_normalize().unwrap_or(Vec3::ZERO);
}
self.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals);