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

Fix Plane UVs / texture flip #8878

Merged
merged 1 commit into from
Jun 18, 2023
Merged

Conversation

Selene-Amanita
Copy link
Member

@Selene-Amanita Selene-Amanita commented Jun 18, 2023

Objective

Fix #1018 (Textures on the Plane shape appear flipped).

This bug have been around for a very long time apparently, I tested it was still there (see test code bellow) and sure enough, this image:

test

... is flipped vertically when used as a texture on a plane (in main, 0.10.1 and 0.9):
image

I'm pretty confused because this bug is so easy to fix, it has been around for so long, it is easy to encounter, and PRs touching this code still didn't fix it: #7546 To the point where I'm wondering if it's actually intended. If it is, please explain why and this PR can be changed to "mention that in the doc".

Solution

Fix the UV mapping on the Plane shape

Here is how it looks after the PR
image

Test code

use bevy::{
    prelude::*,
};

fn main () {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(
    mut commands: Commands,
    assets: ResMut<AssetServer>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(0., 3., 0.).looking_at(Vec3::ZERO, Vec3::NEG_Z),
        ..default()
    });

    let mesh = meshes.add(Mesh::from(shape::Plane::default()));
    let texture_image = assets.load("test.png");
    let material = materials.add(StandardMaterial { 
        base_color_texture: Some(texture_image),
        ..default()
    });
    commands.spawn(PbrBundle {
        mesh,
        material,
        ..default()
    });
}

Changelog

Fix textures on Plane shapes being flipped vertically.

Migration Guide

Flip the textures you use on Plane shapes.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. This is correct. If you place the camera "above" the plane with the camera facing down ("forward" aligned with -Y and "up" aligned with -Z), the image should have the "default" orientation. This fixes that.

@cart cart added this pull request to the merge queue Jun 18, 2023
Merged via the queue into bevyengine:main with commit 6c86545 Jun 18, 2023
@Selene-Amanita Selene-Amanita deleted the fix-plane-uvs branch June 18, 2023 20:00
NoahShomette pushed a commit to NoahShomette/bevy that referenced this pull request Jun 19, 2023
# Objective

Fix bevyengine#1018 (Textures on the
`Plane` shape appear flipped).

This bug have been around for a very long time apparently, I tested it
was still there (see test code bellow) and sure enough, this image:


![test](https://github.com/bevyengine/bevy/assets/134181069/4cda7cf8-57d9-4677-91f5-02240d1e79b1)

... is flipped vertically when used as a texture on a plane (in main,
0.10.1 and 0.9):

![image](https://github.com/bevyengine/bevy/assets/134181069/0db4f52a-51af-4041-9c45-7bfe1f08b0cc)

I'm pretty confused because this bug is so easy to fix, it has been
around for so long, it is easy to encounter, and PRs touching this code
still didn't fix it: bevyengine#7546 To the
point where I'm wondering if it's actually intended. If it is, please
explain why and this PR can be changed to "mention that in the doc".

## Solution

Fix the UV mapping on the Plane shape

Here is how it looks after the PR

![image](https://github.com/bevyengine/bevy/assets/134181069/e07ce641-3de8-4da3-a4f3-95a6054c86d7)

## Test code

```rust
use bevy::{
    prelude::*,
};

fn main () {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(
    mut commands: Commands,
    assets: ResMut<AssetServer>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(0., 3., 0.).looking_at(Vec3::ZERO, Vec3::NEG_Z),
        ..default()
    });

    let mesh = meshes.add(Mesh::from(shape::Plane::default()));
    let texture_image = assets.load("test.png");
    let material = materials.add(StandardMaterial { 
        base_color_texture: Some(texture_image),
        ..default()
    });
    commands.spawn(PbrBundle {
        mesh,
        material,
        ..default()
    });
}
```

## Changelog

Fix textures on `Plane` shapes being flipped vertically.

## Migration Guide

Flip the textures you use on `Plane` shapes.
@Selene-Amanita Selene-Amanita added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issue with shape::plane uv or indices order
2 participants