Skip to content

Commit

Permalink
Add outline for selection
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed May 19, 2024
1 parent 946a1f8 commit b7c5fe5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/editor_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ bevy_egui.workspace = true
egui_dock.workspace = true
egui-toast.workspace = true

bevy_mod_outline = {version = "0.7.0", optional = true}

[features]
default = ["persistence_editor", "bevy_mod_outline"]
persistence_editor = []
bevy_mod_outline = ["dep:bevy_mod_outline"]

[lints]
workspace = true
58 changes: 52 additions & 6 deletions crates/editor_core/src/selected.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use bevy::{
pbr::wireframe::{Wireframe, WireframePlugin},
prelude::*,
};
use bevy::prelude::*;

#[cfg(not(feature = "bevy_mod_outline"))]
use bevy::pbr::wireframe::{Wireframe, WireframePlugin};

use space_shared::{EditorSet, EditorState};

#[cfg(feature = "bevy_mod_outline")]
use bevy_mod_outline::{OutlineBundle, OutlinePlugin, OutlineVolume};

/// A marker for editor selected entities
#[derive(Component, Default, Clone)]
pub struct Selected;
Expand All @@ -14,8 +17,17 @@ pub struct SelectedPlugin;

impl Plugin for SelectedPlugin {
fn build(&self, app: &mut App) {
if !app.is_plugin_added::<WireframePlugin>() {
app.add_plugins(WireframePlugin);
#[cfg(not(feature = "bevy_mod_outline"))]
{
if !app.is_plugin_added::<WireframePlugin>() {
app.add_plugins(WireframePlugin);
}
}
#[cfg(feature = "bevy_mod_outline")]
{
if !app.is_plugin_added::<OutlinePlugin>() {
app.add_plugins(OutlinePlugin);
}
}
app.add_systems(
Update,
Expand All @@ -25,6 +37,7 @@ impl Plugin for SelectedPlugin {
}
}

#[cfg(not(feature = "bevy_mod_outline"))]
fn selected_entity_wireframe_update(
mut cmds: Commands,
del_wireframe: Query<Entity, (With<Wireframe>, Without<Selected>)>,
Expand All @@ -39,13 +52,46 @@ fn selected_entity_wireframe_update(
}
}

#[cfg(not(feature = "bevy_mod_outline"))]
fn clear_wireframes(mut cmds: Commands, del_wireframe: Query<Entity, With<Wireframe>>) {
for e in del_wireframe.iter() {
cmds.entity(e).remove::<Wireframe>();
}
}

#[cfg(feature = "bevy_mod_outline")]
fn selected_entity_wireframe_update(
mut cmds: Commands,
del_wireframe: Query<Entity, (With<OutlineVolume>, Without<Selected>)>,
need_wireframe: Query<Entity, (Without<OutlineVolume>, With<Selected>)>,
) {
for e in del_wireframe.iter() {
cmds.entity(e).remove::<OutlineBundle>();
}

for e in need_wireframe.iter() {
cmds.entity(e).insert(OutlineBundle {
outline: OutlineVolume {
visible: true,
colour: Color::YELLOW,
width: 2.0,
..Default::default()
},
mode: bevy_mod_outline::OutlineMode::RealVertex,
..Default::default()
});
}
}

#[cfg(feature = "bevy_mod_outline")]
fn clear_wireframes(mut cmds: Commands, del_wireframe: Query<Entity, With<OutlineVolume>>) {
for e in del_wireframe.iter() {
cmds.entity(e).remove::<OutlineBundle>();
}
}

#[cfg(test)]
#[cfg(not(feature = "bevy_mod_outline"))]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/editor_ui/src/inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl EditorTab for InspectorTab {
) {
editor_camera_enabled.0 = false;
} else {
error!("Failed to get editor camera config");
// error!("Failed to get editor camera config");
}
}

Expand Down

0 comments on commit b7c5fe5

Please sign in to comment.