mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Add a test for Mesh::compute_smooth_normals (#16038)
# Objective - Code is safer with tests ## Solution - Add a test ## Testing - Test added
This commit is contained in:
parent
3eec0f0a77
commit
2e2d669406
1 changed files with 35 additions and 0 deletions
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue