bevyengine / bevyengine/bevy

Mesh2d primitive normals feel reversed when using `Camera3d`

Open
#19,837 5 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version
0.16.1

## What you did

```rust
use bevy::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
Camera3d::default(),
Transform::default().looking_at(Vec3::splat(100.), Vec3::Y),
));
commands.spawn((
Mesh3d(meshes.add(Rectangle::new(10., 10.))),
MeshMaterial3d(materials.add(StandardMaterial::default())),
Transform::from_translation(Vec3::splat(50.)).looking_at(Vec3::ZERO, Vec3::Y),
));
}
```

## What went wrong

I expected to see a rectangle in the center of my window. ~~IceSentry mentioned that this is okay for 2d meshes/sprites with 2d cameras as the ["default mesh pipeline for both don't have any culling."](https://discord.com/channels/691052431525675048/691052431974465548/1387993189310267574)~~

The working code in this case would be something like

```rust
fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
Camera3d::default(),
Transform::default().looking_at(Vec3::splat(100.), Vec3::Y),
));
commands.spawn((
Mesh3d(meshes.add(Rectangle::new(10., 10.))),
MeshMaterial3d(materials.add(StandardMaterial::default())),
Transform::from_translation(Vec3::splat(50.)).looking_at(Vec3::splat(100.), Vec3::Y),
));
}
```

I have run into this before. For meshes you want to point towards the camera implies you should have to calculate the direction of the ray to the center of the mesh, which feels unintuitive.

## Additional information

This issue is the product of the following conversation in discord https://discord.com/channels/691052431525675048/691052431974465548/1387985132668846292

The original implementation: https://github.com/bevyengine/bevy/pull/11431

Note: it seems the solution is pretty straight forward. However, I don't know if reversing these is a *good idea*, even if it's unintuitive to me :)

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Bevy 0.16.1 setup and compare its two transform orientations. Read the original implementation in PR #11431 and the linked Discord discussion to understand the intended Mesh2d normal and winding convention. Done means deciding whether the primitive orientation should change and verifying the resulting rectangle renders as expected through Camera3d.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.