Skip to content

Commit 24b21ea

Browse files
committed
Fix torus normals (#3549)
# Objective Fixes #3547 ## Solution Normal calc adapted from https://web.cs.ucdavis.edu/~amenta/s12/findnorm.pdf ## Before <img width="1392" alt="before" src="https://user-images.githubusercontent.com/200550/148125212-fb1c083e-3c57-4330-a656-df34513c36ab.png"> ## After <img width="1392" alt="after" src="https://user-images.githubusercontent.com/200550/148125223-174dc956-37df-4ac2-8983-b18e1e2a9a7d.png"> I'm assuming that the greyness and the self-shadowing artifacts are... normal for the new renderer.
1 parent b9c623e commit 24b21ea

File tree

1 file changed

+8
-2
lines changed
  • crates/bevy_render/src/mesh/shape

1 file changed

+8
-2
lines changed

crates/bevy_render/src/mesh/shape/torus.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl From<Torus> for Mesh {
3737

3838
for segment in 0..=torus.subdivisions_segments {
3939
let theta = segment_stride * segment as f32;
40-
let segment_pos = Vec3::new(theta.cos(), 0.0, theta.sin() * torus.radius);
4140

4241
for side in 0..=torus.subdivisions_sides {
4342
let phi = side_stride * side as f32;
@@ -46,7 +45,14 @@ impl From<Torus> for Mesh {
4645
let z = theta.sin() * (torus.radius + torus.ring_radius * phi.cos());
4746
let y = torus.ring_radius * phi.sin();
4847

49-
let normal = segment_pos.cross(Vec3::Y).normalize();
48+
let tan_ring = Vec3::new(
49+
theta.cos() * phi.sin() * -1.0,
50+
theta.sin() * phi.sin() * -1.0,
51+
phi.cos(),
52+
);
53+
let tan = Vec3::new(theta.sin() * -1.0, theta.cos(), 0.0);
54+
55+
let normal = tan.cross(tan_ring).normalize();
5056

5157
positions.push([x, y, z]);
5258
normals.push(normal.into());

0 commit comments

Comments
 (0)