From 81506301e0cf537239c8c45839a7ae44c5c1a00c Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 4 Jan 2022 14:05:47 -0700 Subject: [PATCH] Fix torus normals --- crates/bevy_render/src/mesh/shape/torus.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/mesh/shape/torus.rs b/crates/bevy_render/src/mesh/shape/torus.rs index 987cb3b230b19..abe63e00c5c27 100644 --- a/crates/bevy_render/src/mesh/shape/torus.rs +++ b/crates/bevy_render/src/mesh/shape/torus.rs @@ -37,7 +37,6 @@ impl From for Mesh { for segment in 0..=torus.subdivisions_segments { let theta = segment_stride * segment as f32; - let segment_pos = Vec3::new(theta.cos(), 0.0, theta.sin() * torus.radius); for side in 0..=torus.subdivisions_sides { let phi = side_stride * side as f32; @@ -46,7 +45,14 @@ impl From for Mesh { let z = theta.sin() * (torus.radius + torus.ring_radius * phi.cos()); let y = torus.ring_radius * phi.sin(); - let normal = segment_pos.cross(Vec3::Y).normalize(); + let tan_ring = Vec3::new( + theta.cos() * phi.sin() * -1.0, + theta.sin() * phi.sin() * -1.0, + phi.cos(), + ); + let tan = Vec3::new(theta.sin() * -1.0, theta.cos(), 0.0); + + let normal = tan.cross(tan_ring).normalize(); positions.push([x, y, z]); normals.push(normal.into());