mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-19 07:53:25 +00:00
Object picking (#8)
This PR implements basic object selection, with help from `bevy_mod_picking` and `bevy_mod_outline`. ### Work Done * Click to select objects in the world * Selected objects become visually highlighted * The selected entity is available globally on the `Res<Selection>` resource * Selected entities can also be queried via the `Selected` marker component * Pressing `F` will "focus" the camera on the selected entity * Pressing `Esc` will clear the active selection ### Known Issues * We're currently using `bevy_mod_picking`'s "Selection" feature, which isn't aware of our own input events. As a consequence, it will select the object under the cursor when releasing `LMB` after orbiting the camera, which is not what we want. This should be pretty easily fixable by dropping `bevy_mod_picking`'s selection feature and reading the object under the cursor in our own click listener that only runs if the LMB event is unhandled. * The skinned mesh is not currently selectable. This is likely fixable by adjusting the logic in `scene::mark_scene_objects`... somehow. The `Gltf` data structure is kind of a nightmare to work with, so this will take some investigation. ### Future Enhancements * For parity with other DCC apps, the "Focus" action should also adjust the camera zoom level to "frame" the selected object in the view. Punting on that for now because I'm not super confident about the math involved. * Group selection with Shift/Ctrl and/or marquee selection would be really nice to have, but probably not critical for now.
This commit is contained in:
+32
-3
@@ -1,8 +1,11 @@
|
||||
#![allow(clippy::type_complexity)]
|
||||
#![allow(clippy::type_complexity, clippy::too_many_arguments)]
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
use bevy_mod_picking::DefaultPickingPlugins;
|
||||
use camera_controller::{CameraController, CameraControllerPlugin, CameraMotionSystem};
|
||||
use input::StudioInputPlugin;
|
||||
use interaction::InteractionPlugin;
|
||||
use math::InterpolationPlugin;
|
||||
use scene::ScenePlugin;
|
||||
use skybox::SkyboxPlugin;
|
||||
@@ -12,6 +15,7 @@ use wasm_bindgen::prelude::*;
|
||||
|
||||
mod camera_controller;
|
||||
mod input;
|
||||
mod interaction;
|
||||
mod math;
|
||||
mod scene;
|
||||
mod skybox;
|
||||
@@ -37,6 +41,9 @@ pub fn init(viewport_size: ViewportSize) {
|
||||
}),
|
||||
..default()
|
||||
}),
|
||||
DefaultPickingPlugins,
|
||||
WorldInspectorPlugin::new(),
|
||||
InteractionPlugin,
|
||||
StudioInputPlugin,
|
||||
InterpolationPlugin,
|
||||
CameraControllerPlugin,
|
||||
@@ -44,10 +51,32 @@ pub fn init(viewport_size: ViewportSize) {
|
||||
SkyboxPlugin,
|
||||
UiLayerPlugin,
|
||||
))
|
||||
.add_systems(Update, draw_world_axes.after(CameraMotionSystem))
|
||||
.insert_resource(GizmoConfig {
|
||||
enabled: true,
|
||||
depth_bias: -0.1,
|
||||
line_perspective: false,
|
||||
line_width: 2.,
|
||||
..default()
|
||||
})
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
update_gizmo_line_thickness,
|
||||
draw_world_axes.after(CameraMotionSystem),
|
||||
),
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn update_gizmo_line_thickness(
|
||||
mut config: ResMut<GizmoConfig>,
|
||||
q_window: Query<&Window, (Changed<Window>, With<PrimaryWindow>)>,
|
||||
) {
|
||||
if let Ok(scale_factor) = q_window.get_single().map(|win| win.scale_factor() as f32) {
|
||||
config.line_width = 2. * scale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_world_axes(mut gizmos: Gizmos, q: Query<&CameraController>) {
|
||||
let &CameraController { focus, radius, .. } = q.single();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user