Skip to content

Commit

Permalink
Add a test for Mesh::compute_smooth_normals (#16038)
Browse files Browse the repository at this point in the history
# Objective

- Code is safer with tests

## Solution

- Add a test

## Testing

- Test added
  • Loading branch information
stepancheg authored Oct 20, 2024
1 parent 3eec0f0 commit 2e2d669
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/bevy_mesh/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,4 +1368,39 @@ mod tests {
vec![3, 2, 1, 0]
);
}

#[test]
fn compute_smooth_normals() {
let mut mesh = Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
);

// z y
// | /
// 3---2
// | / \
// 0-----1--x

mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
vec![[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
);
mesh.insert_indices(Indices::U16(vec![0, 1, 2, 0, 2, 3]));
mesh.compute_smooth_normals();
let normals = mesh
.attribute(Mesh::ATTRIBUTE_NORMAL)
.unwrap()
.as_float3()
.unwrap();
assert_eq!(4, normals.len());
// 0
assert_eq!(Vec3::new(1., 0., 1.).normalize().to_array(), normals[0]);
// 1
assert_eq!([0., 0., 1.], normals[1]);
// 2
assert_eq!(Vec3::new(1., 0., 1.).normalize().to_array(), normals[2]);
// 3
assert_eq!([1., 0., 0.], normals[3]);
}
}

0 comments on commit 2e2d669

Please sign in to comment.