@@ -3,27 +3,45 @@ title: Smooth normals implementation changed
3
3
pull_requests : [18552]
4
4
---
5
5
6
- In Bevy 0.16, ` Mesh ` smooth normal calculation used a face area-weighted
7
- algorithm. In 0.17, the area-weighted method was moved to separate methods,
6
+ In Bevy 0.16, ` Mesh ` smooth normal calculation used a triangle area-weighted
7
+ algorithm. In 0.17, the area-weighted algorithm was moved to separate methods,
8
8
the default implementation was switched to a corner angle-weighted algorithm,
9
9
and ` Mesh::compute_custom_smooth_normals ` was added for other cases.
10
10
11
11
The angle-weighted method is more suitable for growing or shrinking a mesh along
12
- its vertex normals, such as for generating an outline mesh. It also results in
13
- more expected lighting behavior in many cases . In most cases, the difference
12
+ its vertex normals, such as when generating an outline mesh. It also results in
13
+ more expected lighting behavior for some meshes . In most cases, the difference
14
14
will be small and no change is needed. However, the new default is somewhat
15
15
slower, and does not always produce the result desired by an artist. If you
16
- preferred the lighting in 0.16, have a significant performance regression,
17
- or needed face -weighted normals for any other reason, you can switch to the
18
- new dedicated face -weighted methods.
16
+ preferred the lighting in 0.16, or have a significant performance regression,
17
+ or needed area -weighted normals for any other reason, you can switch to the
18
+ new dedicated area -weighted methods.
19
19
20
20
``` diff
21
21
// Only if the new smooth normals algorithm is unsatisfactory:
22
22
23
23
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, default())
24
+ .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
24
25
- .with_computed_smooth_normals();
25
- + .with_computed_face_weighted_normals ;
26
+ + .with_computed_area_weighted_normals ;
26
27
27
28
- mesh.compute_smooth_normals();
28
- + mesh.compute_face_weighted_normals;
29
+ + mesh.compute_area_weighted_normals();
30
+ ```
31
+
32
+ As part of this change, the helper functions ` face_normal ` and
33
+ ` face_area_normal ` , were renamed to ` triangle_normal ` and ` triangle_area_normal `
34
+ respectively to better reflect the fact that they do not take an entire
35
+ geometric face into account.
36
+
37
+ ``` diff
38
+ - use bevy::render::mesh::face_normal;
39
+ - let normal = face_normal(a, b, c);
40
+ + use bevy::render::mesh::triangle_normal;
41
+ + let normal = triangle_normal(a, b, c);
42
+
43
+ - use bevy::render::mesh::face_area_normal;
44
+ - let normal = face_area_normal(a, b, c);
45
+ + use bevy::render::mesh::triangle_area_normal;
46
+ + let normal = triangle_area_normal(a, b, c);
29
47
```
0 commit comments