Add material library and targeted surface drops
This commit is contained in:
1 parent
3931de1f0a
commit
02247f029a
24 files changed
+2794
-150
No files matched your search
@@ -1855,7 +1855,7 @@ fn details_panel(world: &mut World, ui: &mut egui::Ui, selected_entities: &Selec
|
||||
}
|
||||
}
|
||||
|
||||
fn top_level_asset_details_panel(
|
||||
pub(crate) fn top_level_asset_details_panel(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
selected_entities: &SelectedEntities,
|
||||
@@ -2524,7 +2524,11 @@ fn save_material_draft(world: &mut World) {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_material_instance_from_base(world: &mut World, base_path: &str, base_label: &str) {
|
||||
pub(crate) fn create_material_instance_from_base(
|
||||
world: &mut World,
|
||||
base_path: &str,
|
||||
base_label: &str,
|
||||
) {
|
||||
let base_reference = world
|
||||
.get_resource_mut::<crate::asset_db::AssetRegistry>()
|
||||
.ok_or_else(|| "Asset registry is unavailable".to_string())
|
||||
|
||||
@@ -36,7 +36,10 @@ impl PanelNodes {
|
||||
EditorTab::Viewport | EditorTab::GameView => self.main_view(),
|
||||
EditorTab::Hierarchy => self.hierarchy(),
|
||||
EditorTab::Inspector => self.inspector(),
|
||||
EditorTab::AssetBrowser | EditorTab::Build | EditorTab::Toolbar => self.bottom(),
|
||||
EditorTab::AssetBrowser
|
||||
| EditorTab::MaterialLibrary
|
||||
| EditorTab::Build
|
||||
| EditorTab::Toolbar => self.bottom(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,20 +54,22 @@ impl PanelNodes {
|
||||
EditorTab::Viewport | EditorTab::GameView => nodes.main_view = path.node.0,
|
||||
EditorTab::Hierarchy => nodes.hierarchy = path.node.0,
|
||||
EditorTab::Inspector => nodes.inspector = path.node.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Build | EditorTab::Toolbar => {
|
||||
nodes.bottom = path.node.0
|
||||
}
|
||||
EditorTab::AssetBrowser
|
||||
| EditorTab::MaterialLibrary
|
||||
| EditorTab::Build
|
||||
| EditorTab::Toolbar => nodes.bottom = path.node.0,
|
||||
}
|
||||
}
|
||||
nodes
|
||||
}
|
||||
}
|
||||
|
||||
pub const PANEL_TABS: [EditorTab; 5] = [
|
||||
pub const PANEL_TABS: [EditorTab; 6] = [
|
||||
EditorTab::Viewport,
|
||||
EditorTab::Hierarchy,
|
||||
EditorTab::Inspector,
|
||||
EditorTab::AssetBrowser,
|
||||
EditorTab::MaterialLibrary,
|
||||
EditorTab::Build,
|
||||
];
|
||||
|
||||
@@ -74,6 +79,7 @@ pub fn tab_label(tab: &EditorTab) -> &'static str {
|
||||
EditorTab::Hierarchy => "Hierarchy",
|
||||
EditorTab::Inspector => "Inspector",
|
||||
EditorTab::AssetBrowser => "Asset Browser",
|
||||
EditorTab::MaterialLibrary => "Material Library",
|
||||
EditorTab::Build => "Build",
|
||||
EditorTab::Toolbar => "Toolbar (legacy)",
|
||||
}
|
||||
|
||||
@@ -32,8 +32,11 @@ pub fn default_dock_layout() -> DockLayoutSnapshot {
|
||||
tree.split_right(NodeIndex::root(), 0.76, vec![EditorTab::Inspector]);
|
||||
let [main_view_node, hierarchy_node] =
|
||||
tree.split_left(main_view_node, 0.2, vec![EditorTab::Hierarchy]);
|
||||
let [main_view_node, bottom_node] =
|
||||
tree.split_below(main_view_node, 0.88, vec![EditorTab::AssetBrowser]);
|
||||
let [main_view_node, bottom_node] = tree.split_below(
|
||||
main_view_node,
|
||||
0.88,
|
||||
vec![EditorTab::AssetBrowser, EditorTab::MaterialLibrary],
|
||||
);
|
||||
|
||||
let panel_nodes = PanelNodes {
|
||||
main_view: main_view_node.0,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,6 +13,7 @@ pub mod hierarchy_ops;
|
||||
pub mod hierarchy_state;
|
||||
pub(crate) mod inspector;
|
||||
mod layout;
|
||||
mod material_library;
|
||||
mod menu;
|
||||
pub(crate) mod navigation_inspector;
|
||||
mod play_controls;
|
||||
@@ -75,6 +76,9 @@ pub struct UiState {
|
||||
last_mode_tab: Option<EditorMode>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
struct DockTabRequest(Option<EditorTab>);
|
||||
|
||||
pub fn egui_captures_keyboard(ctx: &egui::Context) -> bool {
|
||||
ctx.egui_wants_keyboard_input()
|
||||
}
|
||||
@@ -187,6 +191,10 @@ impl UiState {
|
||||
.show_inside(root_ui, &mut viewer);
|
||||
});
|
||||
|
||||
if let Some(tab) = world.resource_mut::<DockTabRequest>().0.take() {
|
||||
dock_tabs::open_and_focus_tab(&mut self.dock_state, tab, &self.panel_nodes);
|
||||
}
|
||||
|
||||
self.panel_nodes = PanelNodes::discover(&self.dock_state, self.panel_nodes);
|
||||
|
||||
mark_layout_dirty_if_changed(
|
||||
@@ -283,6 +291,7 @@ pub enum EditorTab {
|
||||
Inspector,
|
||||
Toolbar,
|
||||
AssetBrowser,
|
||||
MaterialLibrary,
|
||||
Build,
|
||||
}
|
||||
|
||||
@@ -298,6 +307,9 @@ impl Plugin for EditorUiPlugin {
|
||||
.init_resource::<component_registry::EditorComponentRegistry>()
|
||||
.init_resource::<crate::rendering_diagnostics::RenderingDiagnosticsPanel>()
|
||||
.init_resource::<asset_browser::AssetBrowserUiState>()
|
||||
.init_resource::<material_library::MaterialLibraryState>()
|
||||
.init_resource::<material_library::MaterialLibraryCatalog>()
|
||||
.init_resource::<DockTabRequest>()
|
||||
.init_resource::<inspector::InspectorClipboard>()
|
||||
.init_resource::<inspector::InspectorPanelState>()
|
||||
.init_resource::<animation_inspector::AnimationInspectorState>()
|
||||
@@ -315,6 +327,10 @@ impl Plugin for EditorUiPlugin {
|
||||
apply_ui_state_from_prefs
|
||||
.after(crate::project_io::load_user_preferences_on_startup),
|
||||
)
|
||||
.add_systems(
|
||||
EguiPrimaryContextPass,
|
||||
material_library::refresh_material_library_catalog.before(show_ui_system),
|
||||
)
|
||||
.add_systems(EguiPrimaryContextPass, show_ui_system)
|
||||
.add_systems(
|
||||
Update,
|
||||
@@ -421,6 +437,9 @@ impl egui_dock::TabViewer for TabViewer<'_> {
|
||||
EditorTab::AssetBrowser => {
|
||||
asset_browser::asset_browser_ui(self.world, ui, self.selected_entities);
|
||||
}
|
||||
EditorTab::MaterialLibrary => {
|
||||
material_library::material_library_ui(self.world, ui, self.selected_entities);
|
||||
}
|
||||
EditorTab::Build => build::build_ui(self.world, ui),
|
||||
}
|
||||
}
|
||||
@@ -432,6 +451,7 @@ impl egui_dock::TabViewer for TabViewer<'_> {
|
||||
EditorTab::Inspector => (icons::SLIDERS, "Inspector"),
|
||||
EditorTab::Toolbar => (icons::WRENCH, "Toolbar"),
|
||||
EditorTab::AssetBrowser => (icons::FOLDER, "Asset Browser"),
|
||||
EditorTab::MaterialLibrary => (icons::PALETTE, "Material Library"),
|
||||
EditorTab::Build => (icons::HAMMER, "Build"),
|
||||
};
|
||||
tab_title(icon, label)
|
||||
|
||||
@@ -7,8 +7,8 @@ use egui_phosphor_icons::icons;
|
||||
use transform_gizmo_bevy::prelude::GizmoOptions;
|
||||
|
||||
use crate::assets::operators::{
|
||||
apply_material_operator, apply_texture_operator, assign_animation_clip_operator,
|
||||
assign_audio_clip_operator, place_asset_operator, place_subasset_operator,
|
||||
assign_animation_clip_operator, assign_audio_clip_operator, place_asset_operator,
|
||||
place_subasset_operator,
|
||||
};
|
||||
use crate::assets::thumbnails::kind_icon;
|
||||
use crate::assets::{AssetSelection, AssetSubAssetKind, EditorAssets};
|
||||
@@ -21,8 +21,8 @@ use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
use crate::viewport::brush_tool::{BrushToolPhase, BrushToolState};
|
||||
use crate::viewport::{
|
||||
snap_translation, viewport_ground_position, EditorViewportMode, ViewportDisplayMode,
|
||||
ViewportSettings,
|
||||
material_drop::is_surface_asset_selection, snap_translation, viewport_ground_position,
|
||||
EditorViewportMode, MaterialDropState, ViewportDisplayMode, ViewportSettings,
|
||||
};
|
||||
|
||||
use super::helpers::{
|
||||
@@ -30,7 +30,8 @@ use super::helpers::{
|
||||
};
|
||||
use super::theme::{
|
||||
overlay_chip_frame, viewport_toolbar_frame, ACCENT, ACCENT_HOVER, AXIS_X, AXIS_Y, AXIS_Z,
|
||||
BORDER, BORDER_STRONG, ELEVATED_BG, SELECTION, SUCCESS, TEXT, TEXT_DIM, TEXT_MUTED, WARNING,
|
||||
BORDER, BORDER_STRONG, ELEVATED_BG, ERROR, SELECTION, SUCCESS, TEXT, TEXT_DIM, TEXT_MUTED,
|
||||
WARNING,
|
||||
};
|
||||
use super::widgets::{
|
||||
icon_button_small, panel_toolbar_row, phosphor_icon, tool_button, tool_button_accent,
|
||||
@@ -69,9 +70,17 @@ pub fn viewport_tab_ui(
|
||||
|
||||
let clean_game_view = world.resource::<ViewportDisplayMode>().clean_game_view;
|
||||
let response = ui.allocate_rect(rect, egui::Sense::HOVER);
|
||||
*viewport_pointer_pos = response
|
||||
.interact_pointer_pos()
|
||||
.or_else(|| response.hover_pos())
|
||||
// A drag source owns egui's interaction response, so `Response::hover_pos()`
|
||||
// is intentionally empty while an asset is dragged over the viewport. The
|
||||
// global pointer position remains available and is the correct input for
|
||||
// drag previews and exact surface targeting.
|
||||
*viewport_pointer_pos = ui
|
||||
.input(|input| {
|
||||
input
|
||||
.pointer
|
||||
.interact_pos()
|
||||
.or_else(|| input.pointer.hover_pos())
|
||||
})
|
||||
.filter(|pos| rect.contains(*pos));
|
||||
*pointer_in_viewport = viewport_pointer_pos.is_some();
|
||||
|
||||
@@ -820,11 +829,44 @@ fn viewport_asset_drop_ui(
|
||||
.resource::<EditorAssets>()
|
||||
.dragging_selection()
|
||||
.cloned();
|
||||
let drag_descriptor = drag_selection
|
||||
let surface_drag = drag_selection
|
||||
.as_ref()
|
||||
.is_some_and(|selection| is_surface_asset_selection(world, selection));
|
||||
let mut drag_descriptor = drag_selection
|
||||
.as_ref()
|
||||
.and_then(|selection| asset_drag_descriptor(world, selection, selected));
|
||||
let over_viewport = pointer_pos.is_some_and(|pos| viewport_rect.contains(pos));
|
||||
let surface_feedback = surface_drag
|
||||
.then(|| world.get_resource::<MaterialDropState>())
|
||||
.flatten()
|
||||
.and_then(MaterialDropState::feedback)
|
||||
.cloned();
|
||||
if surface_drag && over_viewport {
|
||||
if let Some((_, _, action)) = drag_descriptor.as_mut() {
|
||||
*action = surface_feedback
|
||||
.as_ref()
|
||||
.map(|feedback| feedback.action.clone())
|
||||
.unwrap_or_else(|| "Finding an assignable surface".into());
|
||||
}
|
||||
}
|
||||
let drop_valid = (surface_drag && over_viewport)
|
||||
.then(|| surface_feedback.as_ref().map(|feedback| feedback.valid))
|
||||
.flatten();
|
||||
let highlight_color = match drop_valid {
|
||||
Some(true) => SUCCESS,
|
||||
Some(false) => ERROR,
|
||||
None => ACCENT_HOVER,
|
||||
};
|
||||
|
||||
let drag_visual_state = if !over_viewport {
|
||||
AssetDragVisualState::Outside
|
||||
} else {
|
||||
match drop_valid {
|
||||
Some(true) => AssetDragVisualState::Valid,
|
||||
Some(false) => AssetDragVisualState::Invalid,
|
||||
None => AssetDragVisualState::Targeted,
|
||||
}
|
||||
};
|
||||
if let (Some(pointer), Some((icon, label, action))) = (pointer_pos, drag_descriptor.as_ref()) {
|
||||
draw_asset_drag_preview(
|
||||
ui,
|
||||
@@ -833,7 +875,7 @@ fn viewport_asset_drop_ui(
|
||||
*icon,
|
||||
label,
|
||||
action,
|
||||
over_viewport,
|
||||
drag_visual_state,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -841,7 +883,7 @@ fn viewport_asset_drop_ui(
|
||||
ui.painter().rect_stroke(
|
||||
viewport_rect.shrink(2.0),
|
||||
0.0,
|
||||
egui::Stroke::new(2.0, ACCENT_HOVER),
|
||||
egui::Stroke::new(2.0, highlight_color),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
}
|
||||
@@ -851,6 +893,11 @@ fn viewport_asset_drop_ui(
|
||||
return;
|
||||
}
|
||||
|
||||
if surface_drag && over_viewport {
|
||||
// The Last-schedule surface-drop session owns exact hit resolution and commit.
|
||||
return;
|
||||
}
|
||||
|
||||
if !pointer_pos.is_some_and(|pos| viewport_rect.contains(pos)) {
|
||||
world.resource_mut::<EditorAssets>().clear_drag();
|
||||
return;
|
||||
@@ -903,26 +950,6 @@ fn viewport_asset_drop_ui(
|
||||
return;
|
||||
}
|
||||
|
||||
if let AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
source_path: Some(path),
|
||||
label,
|
||||
..
|
||||
} = &selection
|
||||
{
|
||||
let asset = crate::assets::EditorAsset {
|
||||
label: label.clone(),
|
||||
path: Some(path.clone()),
|
||||
folder_path: std::path::Path::new(path)
|
||||
.parent()
|
||||
.map(|parent| parent.to_string_lossy().replace('\\', "/"))
|
||||
.unwrap_or_else(|| crate::assets::ASSETS_ROOT.to_string()),
|
||||
kind: crate::assets::EditorAssetKind::Texture,
|
||||
};
|
||||
apply_texture_operator(world, asset, selected);
|
||||
return;
|
||||
}
|
||||
|
||||
let asset = {
|
||||
let assets = world.resource::<EditorAssets>();
|
||||
assets.asset_for_selection(&selection).cloned()
|
||||
@@ -943,18 +970,6 @@ fn viewport_asset_drop_ui(
|
||||
}
|
||||
return;
|
||||
}
|
||||
match asset.kind {
|
||||
crate::assets::EditorAssetKind::Texture => {
|
||||
apply_texture_operator(world, asset, selected);
|
||||
return;
|
||||
}
|
||||
crate::assets::EditorAssetKind::Material => {
|
||||
apply_material_operator(world, asset, selected);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
place_asset_operator(world, asset, placement);
|
||||
}
|
||||
|
||||
@@ -996,11 +1011,11 @@ fn asset_drag_descriptor(
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Texture,
|
||||
..
|
||||
} if !selected.is_empty() => "Apply texture to selection",
|
||||
} => "Drop onto a primitive or brush face",
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Material,
|
||||
..
|
||||
} if !selected.is_empty() => "Apply material to selection",
|
||||
} => "Drop onto an exact renderer slot",
|
||||
AssetSelection::SubAsset {
|
||||
kind: AssetSubAssetKind::Skeleton,
|
||||
..
|
||||
@@ -1020,12 +1035,8 @@ fn asset_drag_descriptor(
|
||||
..
|
||||
} => "Create animated actor",
|
||||
_ => match asset.kind {
|
||||
crate::assets::EditorAssetKind::Texture if !selected.is_empty() => {
|
||||
"Apply texture to selection"
|
||||
}
|
||||
crate::assets::EditorAssetKind::Material if !selected.is_empty() => {
|
||||
"Apply material to selection"
|
||||
}
|
||||
crate::assets::EditorAssetKind::Texture => "Drop onto a primitive or brush face",
|
||||
crate::assets::EditorAssetKind::Material => "Drop onto a renderable surface",
|
||||
crate::assets::EditorAssetKind::AudioClip
|
||||
if selected
|
||||
.as_slice()
|
||||
@@ -1041,6 +1052,29 @@ fn asset_drag_descriptor(
|
||||
Some((icon, label, action.to_string()))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum AssetDragVisualState {
|
||||
Outside,
|
||||
Targeted,
|
||||
Valid,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
impl AssetDragVisualState {
|
||||
fn over_viewport(self) -> bool {
|
||||
self != Self::Outside
|
||||
}
|
||||
|
||||
fn color(self) -> egui::Color32 {
|
||||
match self {
|
||||
Self::Outside => TEXT_DIM,
|
||||
Self::Targeted => ACCENT_HOVER,
|
||||
Self::Valid => SUCCESS,
|
||||
Self::Invalid => ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_asset_drag_preview(
|
||||
ui: &egui::Ui,
|
||||
viewport_rect: egui::Rect,
|
||||
@@ -1048,39 +1082,41 @@ fn draw_asset_drag_preview(
|
||||
icon: egui_phosphor_icons::Icon,
|
||||
label: &str,
|
||||
action: &str,
|
||||
over_viewport: bool,
|
||||
visual_state: AssetDragVisualState,
|
||||
) {
|
||||
let over_viewport = visual_state.over_viewport();
|
||||
let highlight_color = visual_state.color();
|
||||
if over_viewport {
|
||||
let painter = ui.painter();
|
||||
painter.circle_filled(pointer, 3.0, ACCENT_HOVER);
|
||||
painter.circle_stroke(pointer, 11.0, egui::Stroke::new(1.5, ACCENT_HOVER));
|
||||
painter.circle_filled(pointer, 3.0, highlight_color);
|
||||
painter.circle_stroke(pointer, 11.0, egui::Stroke::new(1.5, highlight_color));
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer - egui::vec2(17.0, 0.0),
|
||||
pointer - egui::vec2(7.0, 0.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
egui::Stroke::new(1.5, highlight_color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer + egui::vec2(7.0, 0.0),
|
||||
pointer + egui::vec2(17.0, 0.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
egui::Stroke::new(1.5, highlight_color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer - egui::vec2(0.0, 17.0),
|
||||
pointer - egui::vec2(0.0, 7.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
egui::Stroke::new(1.5, highlight_color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
pointer + egui::vec2(0.0, 7.0),
|
||||
pointer + egui::vec2(0.0, 17.0),
|
||||
],
|
||||
egui::Stroke::new(1.5, ACCENT_HOVER),
|
||||
egui::Stroke::new(1.5, highlight_color),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1101,7 +1137,7 @@ fn draw_asset_drag_preview(
|
||||
ui.set_width(228.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icon, 20.0).color(if over_viewport {
|
||||
ACCENT_HOVER
|
||||
highlight_color
|
||||
} else {
|
||||
TEXT_DIM
|
||||
}));
|
||||
@@ -1116,7 +1152,7 @@ fn draw_asset_drag_preview(
|
||||
})
|
||||
.size(11.0)
|
||||
.color(if over_viewport {
|
||||
ACCENT_HOVER
|
||||
highlight_color
|
||||
} else {
|
||||
TEXT_MUTED
|
||||
}),
|
||||
@@ -1152,9 +1188,9 @@ fn draw_asset_drag_preview(
|
||||
),
|
||||
] {
|
||||
ui.painter()
|
||||
.line_segment([a, a + b], egui::Stroke::new(3.0, ACCENT_HOVER));
|
||||
.line_segment([a, a + b], egui::Stroke::new(3.0, highlight_color));
|
||||
ui.painter()
|
||||
.line_segment([a, a + c], egui::Stroke::new(3.0, ACCENT_HOVER));
|
||||
.line_segment([a, a + c], egui::Stroke::new(3.0, highlight_color));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user