Skip to content

Add OutlineGizmoPlugin and integrate outline gizmo functionality #195

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
merged 16 commits into from
Jun 12, 2025

Conversation

jbuehler23
Copy link
Contributor

@jbuehler23 jbuehler23 commented Jun 3, 2025

First cut at getting an Outline Gizmo working - very rough, and highly WIP while learning the ins and outs of bevy and the repo :)

My first thoughts are that it seems incredibly verbose to create a toggle which is updated by some "listener".

It would be nice if this block could be heavily simplified:

parent
        .spawn((
            Node {
                position_type: PositionType::Absolute,
                top: Val::Px(10.0),
                left: Val::Px(10.0),
                width: Val::Px(120.0),
                height: Val::Px(30.0),
                align_items: AlignItems::Center,
                justify_content: JustifyContent::Center,
                ..default()
            },
            BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
        ))
        .with_children(|parent| {
            parent.spawn((
                Text::new(""),
                GizmoToggleText,
            ));
        })
        .observe(|_trigger: Trigger<Pointer<Click>>, mut show_outlines: ResMut<ShowOutlines>| {
            show_outlines.0 = !show_outlines.0;
        });

// System to update the button text when ShowOutlines changes
fn update_gizmo_toggle_text(
    show_outlines: Res<ShowOutlines>,
    mut query: Query<&mut Text, With<GizmoToggleText>>,
) {
    if show_outlines.is_changed() {
        for mut text in &mut query {
            text.0 = if show_outlines.0 { "Hide Outlines".into() } else { "Show Outlines".into() };
        }
    }
}

into something with a more simplified callback structure.

This is also a first step toward the Milestone Issue we have here: #197

Also adds documentation outlined in #207 to give new devs help when trying compile/run changes locally

Screenshot of toggle button working on the editor locally :)

image

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I'm happy with the code here: verbose but clear. Toss in a screenshot to the PR description and I'll merge this for you.

@alice-i-cecile alice-i-cecile added the C-Feature Make something new possible label Jun 4, 2025
@jbuehler23
Copy link
Contributor Author

I actually can’t get the toggle to display in the pane. Could use some advice on here if possible?

@jbuehler23 jbuehler23 added the S-Needs-Investigation This issue requires detective work to figure out what's going wrong label Jun 6, 2025
@alice-i-cecile
Copy link
Member

I generally set up my IDE to format on save to reduce the CI headaches while working on Rust projects :)

@jbuehler23
Copy link
Contributor Author

@alice-i-cecile think this is ready to be merged now - i've also mentioned #207 in this one - not sure if that autolinks the Issue to this PR though (ie, once merged, will it close that Issue?)

@jbuehler23 jbuehler23 linked an issue Jun 11, 2025 that may be closed by this pull request
}
}

// Marker component for selected entities
Copy link
Contributor

Choose a reason for hiding this comment

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

There already is a SelectedEntity resource defined in bevy_editor_core, you should not define your own component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done - i've added bevy_editor_core to the cargo.toml for bevy_3d_viewport

top: Val::Px(20.0),
right: Val::Px(20.0),
width: Val::Px(150.0),
height: Val::Px(15.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

The height of this button is smaller than the text inside which is not very pleasing to look at.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i've fixed thisi by making the font smaller for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

}
}

pub fn spawn_gizmo_toggle_ui(mut commands: Commands) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be only a temporary solution, it would be better to have a menu to manage which gizmo types are visible just like other game engines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i agree with this - but beyond the scope of this PR. I just wanted to add something quick and dirty to show that we can add the outlines

project::update_project_info();

// project::update_project_info();
println!("Loading Bevy Editor");
Copy link
Contributor

Choose a reason for hiding this comment

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

You should rather use info!.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

},
Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y),
));
fn load_example_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will crash the editor when it is not run as the example. This should be somehow integrated into the example code instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i've removed this for now

Copy link
Contributor

Choose a reason for hiding this comment

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

This is an invalid scene!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i've removed loading this for now

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Investigation This issue requires detective work to figure out what's going wrong labels Jun 12, 2025
…ctedEntity struct, remove example scene loading, and fix "Show Outlines" button
@jbuehler23
Copy link
Contributor Author

@Constanze3 Thanks for the constructive review! This was so helpful, and I've made those changes you've recommended. I've also removed the example scene loading for now, until we come up with a more elegant solution.

@@ -46,8 +46,8 @@ pub struct EditorPlugin;
impl Plugin for EditorPlugin {
fn build(&self, bevy_app: &mut BevyApp) {
// Update/register this project to the editor project list
project::update_project_info();

// project::update_project_info();
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this commented out intentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh strange, that must've been an accident on my end - apols

@@ -14,7 +14,7 @@ impl Plugin for EditorCorePlugin {
}

/// The currently selected entity in the scene.
#[derive(Resource, Default, Reflect)]
#[derive(Component, Resource, Default, Reflect)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not how you should do this. This should not be a component.

Instead in your gizmo system you should have a query: Query<&Transform> and also grab selected_entity: Res<SelectedEntity> and then use query.get(selected_entity.0) to get the transform of the selected entity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Thanks for the tip

…te gizmo color logic - also reverts Component derive from SelectedEntity
@jbuehler23 jbuehler23 added S-Ready-For-Final-Review This PR is ready to be merged. Go for it! and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 12, 2025
@jbuehler23 jbuehler23 added this pull request to the merge queue Jun 12, 2025
Merged via the queue into main with commit 5dcfd5e Jun 12, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Feature Make something new possible S-Ready-For-Final-Review This PR is ready to be merged. Go for it!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document run steps to get editor changes built and compiled locally
3 participants