Skip to content

Commit 5dcfd5e

Browse files
authored
Add OutlineGizmoPlugin and integrate outline gizmo functionality (#195)
* Add OutlineGizmoPlugin and integrate outline gizmo functionality * cargo format * Refactor outline gizmo UI spawning and update plugin system integration * Remove unused function import from outline_gizmo in 3D viewport module * Refactor outline_gizmo system setup and add example scene asset * Add debug print statements in View Gizmo and Bevy Editor setup * Replace println! with info! for better logging in outline_gizmo, view_gizmo, and lib modules * Adjust UI layout in spawn_gizmo_toggle_ui and add example scene asset also add documentation about compiling the editor locally and running with local changes * Remove VSCode launch configuration file * Add missing workspace dependency for bevy_editor_core and update SelectedEntity struct, remove example scene loading, and fix "Show Outlines" button * Remove unused import of TextStyles in outline_gizmo.rs * Refactor outline_gizmo_system to use SelectedEntity resource and update gizmo color logic - also reverts Component derive from SelectedEntity
1 parent cd28a9e commit 5dcfd5e

File tree

8 files changed

+145
-2
lines changed

8 files changed

+145
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Want to see what we have planned? Check out [design-book/vision] for a high-leve
1010
Want to help? See [design-book/roadmap] for an up-to-date summary of the work that has been done and needs to be done to advance the project to the next phase.
1111
To avoid ballooning scope and ensure we can ship something useful and reasonably polished, please try your best to focus efforts on the next milestone that has yet to be completed, or standalone proof-of-concepts or design work for important open questions.
1212

13+
*IMPORTANT*:
14+
15+
When you open a folder with the launcher it will simply copy the template to the target location which references the editor's github repository and not your locally compiled editor.
16+
17+
Instead, for local editor dev use the below example for compiling/running changes:
18+
19+
`cargo run --example simple_editor`
20+
21+
1322
## Figma Designs
1423

1524
While laying out the foundations for an editor prototype in this repository, we are also experimenting with various UI designs in a public [Figma document]. If you are interested in collaborating and sharing your own designs, head over to the document and request write permissions to join the effort.

assets/example/scene.scn.ron

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(
2+
entities: [
3+
(
4+
components: [
5+
(bevy_transform::components::Transform, (
6+
translation: (1.0, 0.0, 0.0),
7+
rotation: (0.0, 0.0, 0.0, 1.0),
8+
scale: (1.0, 1.0, 1.0),
9+
)),
10+
(bevy_render::color::Color, (r: 0.8, g: 0.2, b: 0.2, a: 1.0)),
11+
],
12+
),
13+
(
14+
components: [
15+
(bevy_transform::components::Transform, (
16+
translation: (0.0, 2.0, 0.0),
17+
rotation: (0.0, 0.0, 0.0, 1.0),
18+
scale: (1.0, 1.0, 1.0),
19+
)),
20+
(bevy_render::color::Color, (r: 0.2, g: 0.8, b: 0.2, a: 1.0)),
21+
],
22+
),
23+
],
24+
)

bevy_editor_panes/bevy_3d_viewport/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bevy_pane_layout.workspace = true
99
bevy_editor_cam.workspace = true
1010
bevy_editor_styles.workspace = true
1111
bevy_infinite_grid.workspace = true
12+
bevy_editor_core.workspace = true
1213

1314
[lints]
1415
workspace = true

bevy_editor_panes/bevy_3d_viewport/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use bevy_infinite_grid::{InfiniteGrid, InfiniteGridPlugin, InfiniteGridSettings}
1818
use bevy_pane_layout::prelude::*;
1919
use view_gizmo::{spawn_view_gizmo_target_texture, ViewGizmoPlugin};
2020

21+
use crate::outline_gizmo::OutlineGizmoPlugin;
22+
23+
mod outline_gizmo;
2124
mod view_gizmo;
2225

2326
/// The identifier for the 3D Viewport.
@@ -44,7 +47,7 @@ impl Plugin for Viewport3dPanePlugin {
4447
app.add_plugins(InfiniteGridPlugin);
4548
}
4649

47-
app.add_plugins((DefaultEditorCamPlugins, ViewGizmoPlugin))
50+
app.add_plugins((DefaultEditorCamPlugins, ViewGizmoPlugin, OutlineGizmoPlugin))
4851
.add_systems(Startup, setup)
4952
.add_systems(
5053
PreUpdate,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use bevy::prelude::*;
2+
use bevy_editor_core::SelectedEntity;
3+
4+
pub struct OutlineGizmoPlugin;
5+
impl Plugin for OutlineGizmoPlugin {
6+
fn build(&self, app: &mut App) {
7+
app.init_resource::<ShowOutlines>()
8+
.add_systems(Startup, spawn_gizmo_toggle_ui)
9+
.add_systems(Update, outline_gizmo_system)
10+
.add_systems(Update, update_gizmo_toggle_text);
11+
}
12+
}
13+
14+
#[derive(Resource, Default)]
15+
pub struct ShowOutlines(pub bool);
16+
17+
// Marker for the toggle button text
18+
#[derive(Component)]
19+
struct GizmoToggleText;
20+
21+
pub fn outline_gizmo_system(
22+
show: Res<ShowOutlines>,
23+
query: Query<&Transform>,
24+
selected_entity: Res<SelectedEntity>,
25+
mut gizmos: Gizmos,
26+
) {
27+
if !show.0 {
28+
return;
29+
}
30+
if let Some(entity) = selected_entity.0 {
31+
if let Ok(transform) = query.get(entity) {
32+
gizmos.cuboid(*transform, Color::srgb(1.0, 0.0, 0.0));
33+
}
34+
}
35+
}
36+
37+
pub fn spawn_gizmo_toggle_ui(mut commands: Commands) {
38+
info!("Spawning Gizmo Toggle UI");
39+
commands
40+
.spawn((
41+
Node {
42+
position_type: PositionType::Absolute,
43+
top: Val::Px(20.0),
44+
right: Val::Px(20.0),
45+
width: Val::Px(100.0),
46+
height: Val::Px(15.0),
47+
align_items: AlignItems::Center,
48+
justify_content: JustifyContent::Center,
49+
..default()
50+
},
51+
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
52+
))
53+
.with_children(|parent| {
54+
parent.spawn((
55+
Text::new("Show Outlines"),
56+
TextFont::from_font_size(10.0),
57+
GizmoToggleText,
58+
));
59+
})
60+
.observe(
61+
|_trigger: Trigger<Pointer<Click>>, mut show_outlines: ResMut<ShowOutlines>| {
62+
show_outlines.0 = !show_outlines.0;
63+
},
64+
);
65+
}
66+
67+
// System to update the button text when ShowOutlines changes
68+
fn update_gizmo_toggle_text(
69+
show_outlines: Res<ShowOutlines>,
70+
mut query: Query<&mut Text, With<GizmoToggleText>>,
71+
) {
72+
if show_outlines.is_changed() {
73+
for mut text in &mut query {
74+
text.0 = if show_outlines.0 {
75+
"Hide Outlines".into()
76+
} else {
77+
"Show Outlines".into()
78+
};
79+
}
80+
}
81+
}

bevy_editor_panes/bevy_3d_viewport/src/view_gizmo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn setup_view_gizmo(
8080
mut materials: ResMut<Assets<StandardMaterial>>,
8181
mut gizmo_assets: ResMut<Assets<GizmoAsset>>,
8282
) {
83+
info!("Spawning View Gizmo");
8384
let view_gizmo_pass_layer = RenderLayers::layer(VIEW_GIZMO_LAYER);
8485
let sphere = meshes.add(Sphere::new(0.2).mesh().uv(32, 18));
8586

crates/bevy_editor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Plugin for EditorPlugin {
4747
fn build(&self, bevy_app: &mut BevyApp) {
4848
// Update/register this project to the editor project list
4949
project::update_project_info();
50-
50+
info!("Loading Bevy Editor");
5151
bevy_app
5252
.add_plugins((
5353
EditorCorePlugin,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(
2+
entities: [
3+
(
4+
components: [
5+
(bevy_transform::components::Transform, (
6+
translation: (1.0, 0.0, 0.0),
7+
rotation: (0.0, 0.0, 0.0, 1.0),
8+
scale: (1.0, 1.0, 1.0),
9+
)),
10+
(bevy_render::color::Color, (r: 0.8, g: 0.2, b: 0.2, a: 1.0)),
11+
],
12+
),
13+
(
14+
components: [
15+
(bevy_transform::components::Transform, (
16+
translation: (0.0, 2.0, 0.0),
17+
rotation: (0.0, 0.0, 0.0, 1.0),
18+
scale: (1.0, 1.0, 1.0),
19+
)),
20+
(bevy_render::color::Color, (r: 0.2, g: 0.8, b: 0.2, a: 1.0)),
21+
],
22+
),
23+
],
24+
)

0 commit comments

Comments
 (0)