Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fix torus normals #3549

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/bevy_render/src/mesh/shape/torus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl From<Torus> 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;
Expand All @@ -46,7 +45,14 @@ impl From<Torus> 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());
Expand Down