bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.45k stars 3.6k forks source link

Text rotation no more working properly #15922

Closed BorisBoutillier closed 1 month ago

BorisBoutillier commented 1 month ago

Bevy version

acbed6040eeae99199657e44a9668772738ac344

What you did

I was looking at issue #15853, and found out that this is the rotation of the text that make it disappear. I wrote the following example, that rotate a text, that showcase the bug:

use bevy::prelude::*;

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

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);
    commands.spawn((
        Text::new("abcdefghijklmnopqrstuvwxyz"),
        TextFont {
            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
            font_size: 40.0,
            ..default()
        },
        TextLayout::new_with_justify(JustifyText::Center),
        Style {
            align_self: AlignSelf::Center,
            justify_self: JustifySelf::Center,
            ..default()
        },
    ));
}

fn text_rotation_system(time: Res<Time>, mut query: Query<&mut Transform, With<Text>>) {
    for mut transform in &mut query {
        let seconds = time.elapsed_seconds();
        transform.rotation = Quat::from_rotation_z(seconds / 2.0);
    }
}

What went wrong

At some small rotation some letters disappear then the whole text disappear. See video:

https://github.com/user-attachments/assets/c941e152-8cca-4dfc-ba84-a995f00f1ff2

Additional information

Fixing this issue should also fix #15863 directly.

BorisBoutillier commented 1 month ago

Further testing shows that this issue IS NOT introduced by the move to required components. The issue is already present the commit just before the Text Rework merge. Namely commit 0b2e0cfacab693e0ddbc1461fbf2190d373197af already has the issue ( need to adapt the provided code).

BorisBoutillier commented 1 month ago

I have been able to bisect the problem and the first bad commit is 675f8ad40380966e3cc9176e95965538df621810, associated to PR #14848

The updated example I used is

use bevy::prelude::*;

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

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((TextBundle::from_section(
        "abcdefghijklmnopqrstuvwxyz",
        TextStyle {
            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
            font_size: 40.0,
            ..default()
        },
    )
    .with_style(Style {
        align_self: AlignSelf::Center,
        justify_self: JustifySelf::Center,
        ..default()
    }),));
}

fn text_rotation_system(time: Res<Time>, mut query: Query<&mut Transform, With<Text>>) {
    for mut transform in &mut query {
        let seconds = time.elapsed_seconds();
        transform.rotation = Quat::from_rotation_z(seconds / 2.0);
    }
}

That is the best I can do with my current knowledge, hope this helps.

ickshonpe commented 1 month ago

The problem is that the UI renderer doesn't support clipping of rotated content properly and it often breaks in unpredictable ways like this.