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] - bevy_render: Fix Quad flip #3741

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
60 changes: 8 additions & 52 deletions crates/bevy_render/src/mesh/shape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl From<Box> for Mesh {
pub struct Quad {
/// Full width and height of the rectangle.
pub size: Vec2,
/// Flips the texture coords of the resulting vertices.
/// Horizontally-flip the texture coordinates of the resulting mesh.
pub flip: bool,
}

Expand All @@ -150,57 +150,13 @@ impl From<Quad> for Mesh {
let extent_x = quad.size.x / 2.0;
let extent_y = quad.size.y / 2.0;

let north_west = vec2(-extent_x, extent_y);
let north_east = vec2(extent_x, extent_y);
let south_west = vec2(-extent_x, -extent_y);
let south_east = vec2(extent_x, -extent_y);
let vertices = if quad.flip {
[
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
]
} else {
[
(
[south_west.x, south_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 1.0],
),
(
[north_west.x, north_west.y, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0],
),
(
[north_east.x, north_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0],
),
(
[south_east.x, south_east.y, 0.0],
[0.0, 0.0, 1.0],
[1.0, 1.0],
),
]
};
let (u_left, u_right) = if quad.flip { (1.0, 0.0) } else { (0.0, 1.0) };
let vertices = [
([-extent_x, -extent_y, 0.0], [0.0, 0.0, 1.0], [u_left, 1.0]),
([-extent_x, extent_y, 0.0], [0.0, 0.0, 1.0], [u_left, 0.0]),
([extent_x, extent_y, 0.0], [0.0, 0.0, 1.0], [u_right, 0.0]),
([extent_x, -extent_y, 0.0], [0.0, 0.0, 1.0], [u_right, 1.0]),
];

let indices = Indices::U32(vec![0, 2, 1, 0, 3, 2]);

Expand Down