Upgrade to Bevy 0.19 and harden editor workflows
CI / Format, lint, test, build (push) Has been cancelled
CI / Format, lint, test, build (push) Has been cancelled
This commit is contained in:
1 parent
3f85d25cc7
commit
b5e561904c
204 files changed
+6972
-29907
No files matched your search
@@ -25,42 +25,27 @@ impl Default for AssetId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum ModelPlacementMode {
|
||||
#[default]
|
||||
StaticAsset,
|
||||
SceneInstance,
|
||||
}
|
||||
|
||||
impl Default for ModelPlacementMode {
|
||||
fn default() -> Self {
|
||||
Self::StaticAsset
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum ModelHierarchyMode {
|
||||
#[default]
|
||||
SingleActor,
|
||||
SourceHierarchy,
|
||||
}
|
||||
|
||||
impl Default for ModelHierarchyMode {
|
||||
fn default() -> Self {
|
||||
Self::SingleActor
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum MaterialImportPolicy {
|
||||
#[default]
|
||||
SourceMaterials,
|
||||
AuthoringOverride,
|
||||
}
|
||||
|
||||
impl Default for MaterialImportPolicy {
|
||||
fn default() -> Self {
|
||||
Self::SourceMaterials
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ImportSettings {
|
||||
pub scale: f32,
|
||||
|
||||
@@ -59,14 +59,13 @@ pub fn apply_texture_operator(
|
||||
) -> bool {
|
||||
let label = format!("Apply Texture {}", asset.label);
|
||||
let availability = selection_availability(world, selected);
|
||||
let selected = selected;
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.apply_texture",
|
||||
&label,
|
||||
availability,
|
||||
move |world| {
|
||||
apply_texture_to_selection(world, &asset, &selected);
|
||||
apply_texture_to_selection(world, &asset, selected);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
@@ -79,14 +78,13 @@ pub fn apply_material_operator(
|
||||
) -> bool {
|
||||
let label = format!("Apply Material {}", asset.label);
|
||||
let availability = selection_availability(world, selected);
|
||||
let selected = selected;
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.apply_material",
|
||||
&label,
|
||||
availability,
|
||||
move |world| {
|
||||
apply_material_asset_to_selection(world, &asset, &selected);
|
||||
apply_material_asset_to_selection(world, &asset, selected);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
|
||||
@@ -206,9 +206,9 @@ fn build_static_mesh_manifest(record: &AssetRecord) -> Result<StaticMeshManifest
|
||||
scale: record.import_settings.scale,
|
||||
generate_collider: record.import_settings.generate_collider,
|
||||
lod0_only: record.import_settings.lod0_only,
|
||||
placement_mode: record.import_settings.placement_mode.clone(),
|
||||
hierarchy_mode: record.import_settings.hierarchy_mode.clone(),
|
||||
material_policy: record.import_settings.material_policy.clone(),
|
||||
placement_mode: record.import_settings.placement_mode,
|
||||
hierarchy_mode: record.import_settings.hierarchy_mode,
|
||||
material_policy: record.import_settings.material_policy,
|
||||
};
|
||||
|
||||
let mut manifest = match format.as_str() {
|
||||
|
||||
@@ -199,7 +199,7 @@ impl AssetThumbnailCache {
|
||||
key.clone(),
|
||||
ThumbnailJobSource::MaterialAsset {
|
||||
label: material.label.clone(),
|
||||
material: material.material,
|
||||
material: Box::new(material.material),
|
||||
},
|
||||
) {
|
||||
self.studio_pending.insert(key);
|
||||
|
||||
@@ -24,7 +24,7 @@ pub enum ThumbnailJobSource {
|
||||
},
|
||||
MaterialAsset {
|
||||
label: String,
|
||||
material: MaterialDesc,
|
||||
material: Box<MaterialDesc>,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ use bevy::math::bounding::Aabb3d;
|
||||
use bevy::mesh::VertexAttributeValues;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::render_resource::TextureFormat;
|
||||
use bevy::scene::SceneRoot;
|
||||
use bevy_egui::EguiUserTextures;
|
||||
use shared::{material_from_desc, ModelRef};
|
||||
|
||||
@@ -134,6 +133,7 @@ fn setup_thumbnail_studio(mut commands: Commands, mut images: ResMut<Assets<Imag
|
||||
ThumbnailStudioLayer,
|
||||
RenderLayers::layer(THUMBNAIL_LAYER),
|
||||
Camera3d::default(),
|
||||
Msaa::Off,
|
||||
Camera {
|
||||
is_active: false,
|
||||
order: -50,
|
||||
@@ -157,7 +157,7 @@ fn setup_thumbnail_studio(mut commands: Commands, mut images: ResMut<Assets<Imag
|
||||
RenderLayers::layer(THUMBNAIL_LAYER),
|
||||
DirectionalLight {
|
||||
illuminance: 12_000.0,
|
||||
shadows_enabled: false,
|
||||
shadow_maps_enabled: false,
|
||||
..default()
|
||||
},
|
||||
Transform::from_rotation(Quat::from_euler(EulerRot::XYZ, -0.8, 0.9, 0.0)),
|
||||
@@ -172,7 +172,7 @@ fn setup_thumbnail_studio(mut commands: Commands, mut images: ResMut<Assets<Imag
|
||||
RenderLayers::layer(THUMBNAIL_LAYER),
|
||||
DirectionalLight {
|
||||
illuminance: 3_500.0,
|
||||
shadows_enabled: false,
|
||||
shadow_maps_enabled: false,
|
||||
..default()
|
||||
},
|
||||
Transform::from_rotation(Quat::from_euler(EulerRot::XYZ, -0.4, -2.2, 0.0)),
|
||||
@@ -380,7 +380,7 @@ fn spawn_thumbnail_job_content(
|
||||
match source {
|
||||
ThumbnailJobSource::Model { model_path } => {
|
||||
if uses_scene_root(model_path) {
|
||||
commands.entity(root).insert(SceneRoot(
|
||||
commands.entity(root).insert(WorldAssetRoot(
|
||||
asset_server.load(model_scene_asset_path(model_path, 0)),
|
||||
));
|
||||
}
|
||||
@@ -494,6 +494,10 @@ fn finish_active_thumbnail(
|
||||
studio.cooldown_frames = COOLDOWN_FRAMES;
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "thumbnail failure coordinates the job, cache, render target, and camera state"
|
||||
)]
|
||||
fn fail_active_thumbnail(
|
||||
commands: &mut Commands,
|
||||
studio: &mut ThumbnailStudio,
|
||||
|
||||
@@ -35,6 +35,12 @@ pub struct EditorCommandRegistry {
|
||||
commands: Vec<Box<dyn EditorCommand>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EditorCommandEntry {
|
||||
pub name: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
impl EditorCommandRegistry {
|
||||
pub fn register(&mut self, command: Box<dyn EditorCommand>) {
|
||||
self.commands.push(command);
|
||||
@@ -47,6 +53,16 @@ impl EditorCommandRegistry {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> Vec<EditorCommandEntry> {
|
||||
self.commands
|
||||
.iter()
|
||||
.map(|command| EditorCommandEntry {
|
||||
name: command.name().to_string(),
|
||||
label: command.label().to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn command_state(&self, world: &World, name: &str) -> Option<(String, Option<String>)> {
|
||||
self.commands
|
||||
.iter()
|
||||
@@ -249,6 +265,10 @@ impl EditorCommand for TogglePlayCommand {
|
||||
"play.toggle"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Toggle Play / Edit"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
@@ -261,6 +281,15 @@ impl EditorCommand for TogglePlayPausedCommand {
|
||||
"play.toggle_pause"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Pause / Resume Simulation"
|
||||
}
|
||||
|
||||
fn disabled_reason(&self, world: &World) -> Option<String> {
|
||||
(*world.resource::<State<EditorMode>>().get() != EditorMode::Playing)
|
||||
.then(|| "Enter Play mode before pausing the simulation".to_string())
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
toggle_play_paused(world);
|
||||
}
|
||||
@@ -273,6 +302,10 @@ impl EditorCommand for TogglePossessionCommand {
|
||||
"play.toggle_possession"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Possess / Eject Player"
|
||||
}
|
||||
|
||||
fn disabled_reason(&self, world: &World) -> Option<String> {
|
||||
(*world.resource::<State<EditorMode>>().get() != EditorMode::Playing)
|
||||
.then(|| "Enter Play mode before toggling possession".to_string())
|
||||
@@ -294,6 +327,10 @@ impl EditorCommand for ResetLightingCommand {
|
||||
"scene.reset_lighting"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Reset Scene Lighting"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
reset_scene_lighting_to_project_defaults(world);
|
||||
}
|
||||
@@ -306,6 +343,10 @@ impl EditorCommand for GroupSelectionCommand {
|
||||
"selection.group"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Group Selection"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
let selected: Vec<Entity> = world
|
||||
.resource::<UiState>()
|
||||
@@ -323,6 +364,10 @@ impl EditorCommand for FocusSelectionCommand {
|
||||
"selection.focus"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Focus Selection"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
focus_editor_camera_on_selection(world);
|
||||
}
|
||||
@@ -335,6 +380,10 @@ impl EditorCommand for ResetSelectionTransformCommand {
|
||||
"selection.reset_transform"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Reset Selection Transform"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
reset_selected_transforms(world);
|
||||
}
|
||||
@@ -428,6 +477,10 @@ impl EditorCommand for CreatePostProcessVolumeCommand {
|
||||
"rendering.create_volume"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Create Post-process Volume"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::spawn_post_process_volume_at_camera(world);
|
||||
}
|
||||
@@ -440,6 +493,10 @@ impl EditorCommand for FocusActiveVolumesCommand {
|
||||
"rendering.focus_active_volumes"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Focus Active Post-process Volumes"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::select_volumes_at_camera(world);
|
||||
focus_editor_camera_on_selection(world);
|
||||
@@ -453,6 +510,10 @@ impl EditorCommand for SelectVolumesAtCameraCommand {
|
||||
"rendering.select_volumes_at_camera"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Select Volumes at Camera"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::select_volumes_at_camera(world);
|
||||
}
|
||||
@@ -471,6 +532,7 @@ fn command_palette_ui(
|
||||
|
||||
if ctx.input(|input| input.modifiers.command && input.key_pressed(egui::Key::P)) {
|
||||
palette.open = true;
|
||||
palette.filter.clear();
|
||||
palette.focus_filter = true;
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
@@ -480,19 +542,20 @@ fn command_palette_ui(
|
||||
}
|
||||
|
||||
let mut open = palette.open;
|
||||
let palette_width = (ctx.content_rect().width() - 32.0).clamp(320.0, 520.0);
|
||||
egui::Window::new("Command Palette")
|
||||
.open(&mut open)
|
||||
.default_width(400.0)
|
||||
.frame(egui::Frame::window(&ctx.style()).fill(PANEL_BG))
|
||||
.anchor(egui::Align2::CENTER_TOP, egui::vec2(0.0, 64.0))
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.default_width(palette_width)
|
||||
.min_width(palette_width)
|
||||
.max_width(palette_width)
|
||||
.frame(egui::Frame::window(&ctx.global_style()).fill(PANEL_BG))
|
||||
.show(ctx, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Ctrl+P — filter and run commands")
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
let filter_response = ui.add(
|
||||
egui::TextEdit::singleline(&mut palette.filter)
|
||||
.hint_text("Type to filter...")
|
||||
.hint_text("Search commands...")
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if palette.focus_filter {
|
||||
@@ -503,35 +566,30 @@ fn command_palette_ui(
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
let filter = palette.filter.to_lowercase();
|
||||
let filtered_names: Vec<String> = registry
|
||||
.names()
|
||||
.into_iter()
|
||||
.filter(|name| filter.is_empty() || name.to_lowercase().contains(&filter))
|
||||
.collect();
|
||||
if !filtered_names.is_empty() {
|
||||
palette.selected_index = palette.selected_index.min(filtered_names.len() - 1);
|
||||
let filtered_entries = filtered_command_entries(®istry, &palette.filter);
|
||||
if !filtered_entries.is_empty() {
|
||||
palette.selected_index = palette.selected_index.min(filtered_entries.len() - 1);
|
||||
} else {
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown))
|
||||
&& !filtered_names.is_empty()
|
||||
&& !filtered_entries.is_empty()
|
||||
{
|
||||
palette.selected_index = (palette.selected_index + 1) % filtered_names.len();
|
||||
palette.selected_index = (palette.selected_index + 1) % filtered_entries.len();
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))
|
||||
&& !filtered_names.is_empty()
|
||||
&& !filtered_entries.is_empty()
|
||||
{
|
||||
palette.selected_index = if palette.selected_index == 0 {
|
||||
filtered_names.len() - 1
|
||||
filtered_entries.len() - 1
|
||||
} else {
|
||||
palette.selected_index - 1
|
||||
};
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) {
|
||||
if let Some(name) = filtered_names.get(palette.selected_index) {
|
||||
palette.pending_run = Some(name.clone());
|
||||
if let Some(entry) = filtered_entries.get(palette.selected_index) {
|
||||
palette.pending_run = Some(entry.name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
@@ -543,18 +601,23 @@ fn command_palette_ui(
|
||||
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(280.0)
|
||||
.max_height(320.0)
|
||||
.show(ui, |ui| {
|
||||
for (index, name) in filtered_names.iter().enumerate() {
|
||||
if filtered_entries.is_empty() {
|
||||
ui.weak("No matching commands");
|
||||
}
|
||||
for (index, entry) in filtered_entries.iter().enumerate() {
|
||||
let selected = index == palette.selected_index;
|
||||
let response =
|
||||
ui.selectable_label(selected, egui::RichText::new(name).color(TEXT));
|
||||
let response = ui.add_sized(
|
||||
[ui.available_width(), 40.0],
|
||||
egui::Button::selectable(selected, command_palette_row(entry)),
|
||||
);
|
||||
if selected {
|
||||
response.scroll_to_me(Some(egui::Align::Center));
|
||||
}
|
||||
if response.clicked() {
|
||||
palette.selected_index = index;
|
||||
palette.pending_run = Some(name.clone());
|
||||
palette.pending_run = Some(entry.name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
@@ -565,3 +628,73 @@ fn command_palette_ui(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn filtered_command_entries(
|
||||
registry: &EditorCommandRegistry,
|
||||
filter: &str,
|
||||
) -> Vec<EditorCommandEntry> {
|
||||
let filter = filter.trim().to_lowercase();
|
||||
registry
|
||||
.entries()
|
||||
.into_iter()
|
||||
.filter(|entry| {
|
||||
filter.is_empty()
|
||||
|| entry.name.to_lowercase().contains(&filter)
|
||||
|| entry.label.to_lowercase().contains(&filter)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn command_palette_row(entry: &EditorCommandEntry) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(
|
||||
&entry.label,
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Proportional),
|
||||
color: TEXT,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.append(
|
||||
&format!("\n{}", entry.name),
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(11.0, egui::FontFamily::Monospace),
|
||||
color: TEXT_DIM,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn command_filter_matches_human_label_and_stable_id() {
|
||||
let mut registry = EditorCommandRegistry::default();
|
||||
registry.register(Box::new(TogglePlayCommand));
|
||||
registry.register(Box::new(ResetLightingCommand));
|
||||
|
||||
let by_label = filtered_command_entries(®istry, "scene lighting");
|
||||
assert_eq!(by_label.len(), 1);
|
||||
assert_eq!(by_label[0].name, "scene.reset_lighting");
|
||||
|
||||
let by_id = filtered_command_entries(®istry, "play.toggle");
|
||||
assert_eq!(by_id.len(), 1);
|
||||
assert_eq!(by_id[0].label, "Toggle Play / Edit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_command_filter_preserves_registration_order() {
|
||||
let mut registry = EditorCommandRegistry::default();
|
||||
registry.register(Box::new(TogglePlayCommand));
|
||||
registry.register(Box::new(ResetLightingCommand));
|
||||
|
||||
let entries = filtered_command_entries(®istry, " ");
|
||||
assert_eq!(entries[0].name, "play.toggle");
|
||||
assert_eq!(entries[1].name, "scene.reset_lighting");
|
||||
}
|
||||
}
|
||||
@@ -282,10 +282,8 @@ pub fn spawn_many_with_history(
|
||||
if snapshots.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut sibling_index = next_sibling_index(world, None);
|
||||
for snapshot in &mut snapshots {
|
||||
for (sibling_index, snapshot) in (next_sibling_index(world, None)..).zip(snapshots.iter_mut()) {
|
||||
snapshot.hierarchy_sibling_index = sibling_index;
|
||||
sibling_index += 1;
|
||||
}
|
||||
let entities: Vec<Entity> = snapshots
|
||||
.iter()
|
||||
@@ -1489,11 +1487,14 @@ fn capture_gizmo_transform_edits(world: &mut World) {
|
||||
Entity,
|
||||
&Transform,
|
||||
&transform_gizmo_bevy::prelude::GizmoTarget,
|
||||
Option<&crate::viewport::brush_edit::BrushElementGizmo>,
|
||||
)>();
|
||||
let active = query
|
||||
.iter(world)
|
||||
.find(|(_, _, target)| target.is_active())
|
||||
.map(|(entity, transform, _)| (entity, *transform));
|
||||
.find(|(_, _, target, brush_element_gizmo)| {
|
||||
brush_element_gizmo.is_none() && target.is_active()
|
||||
})
|
||||
.map(|(entity, transform, _, _)| (entity, *transform));
|
||||
|
||||
let start_group =
|
||||
active.map(|(entity, transform)| selected_transforms(world, &selection, entity, transform));
|
||||
|
||||
@@ -24,7 +24,6 @@ pub use play::net_editor;
|
||||
pub use play::state;
|
||||
pub use project::project_io;
|
||||
pub use project::settings_ui;
|
||||
pub use project::workspace;
|
||||
pub use scene::scene_io;
|
||||
pub use scene::scene_schema;
|
||||
pub use scene::scene_view;
|
||||
@@ -81,7 +80,6 @@ impl PluginGroup for EditorPluginGroup {
|
||||
let group = PluginGroupBuilder::start::<Self>()
|
||||
.add(EditorInfraPlugin)
|
||||
.add(ProjectIoPlugin)
|
||||
.add(workspace::WorkspacePlugin)
|
||||
.add(scene_schema::SceneSchemaPlugin)
|
||||
.add(net_editor::NetEditorPlugin)
|
||||
.add(AssetDbPlugin)
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
|
||||
pub mod project_io;
|
||||
pub mod settings_ui;
|
||||
pub mod workspace;
|
||||
@@ -1,150 +0,0 @@
|
||||
//! Project workspace New/Open and recent scene switcher (H2).
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use settings::{
|
||||
load_project_settings_from_path, ProjectSettings, ProjectSettingsIo, DEFAULT_PROJECT_PATH,
|
||||
};
|
||||
|
||||
use crate::history::EditorHistory;
|
||||
use crate::project_io::{push_recent, ProjectWorkspace, UserPreferences};
|
||||
use crate::scene_io::{SceneIo, SceneIoRequest};
|
||||
|
||||
pub struct WorkspacePlugin;
|
||||
|
||||
impl Plugin for WorkspacePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<WorkspaceState>()
|
||||
.init_resource::<WorkspaceIoRequest>()
|
||||
.add_systems(Update, process_workspace_requests);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct WorkspaceState {
|
||||
pub project_name: String,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default, Debug)]
|
||||
pub struct WorkspaceIoRequest {
|
||||
pub new_project: bool,
|
||||
pub open_project: bool,
|
||||
}
|
||||
|
||||
pub fn request_new_project(world: &mut World) {
|
||||
world.resource_mut::<WorkspaceIoRequest>().new_project = true;
|
||||
}
|
||||
|
||||
pub fn request_open_project(world: &mut World) {
|
||||
world.resource_mut::<WorkspaceIoRequest>().open_project = true;
|
||||
}
|
||||
|
||||
pub fn request_open_recent_scene(world: &mut World, index: usize) {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::OpenRecent(index));
|
||||
}
|
||||
|
||||
pub fn sync_recent_levels_to_scene_io(world: &mut World) {
|
||||
let recent: Vec<PathBuf> = world
|
||||
.resource::<UserPreferences>()
|
||||
.recent_levels
|
||||
.iter()
|
||||
.map(PathBuf::from)
|
||||
.collect();
|
||||
world.resource_mut::<SceneIo>().recent_paths = recent;
|
||||
}
|
||||
|
||||
pub fn remember_opened_level(world: &mut World, path: String) {
|
||||
if let Some(mut prefs) = world.get_resource_mut::<UserPreferences>() {
|
||||
push_recent(&mut prefs.recent_levels, path, 8);
|
||||
let _ = crate::project_io::write_user_preferences(&prefs);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_workspace_requests(world: &mut World) {
|
||||
let (new_project, open_project) = {
|
||||
let mut req = world.resource_mut::<WorkspaceIoRequest>();
|
||||
let new_project = req.new_project;
|
||||
let open_project = req.open_project;
|
||||
req.new_project = false;
|
||||
req.open_project = false;
|
||||
(new_project, open_project)
|
||||
};
|
||||
|
||||
if new_project {
|
||||
world.resource_mut::<SceneIo>().status = apply_new_project(world);
|
||||
} else if open_project {
|
||||
world.resource_mut::<SceneIo>().status = apply_open_project(world);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_new_project(world: &mut World) -> String {
|
||||
let default_settings = ProjectSettings::default();
|
||||
let settings_path = DEFAULT_PROJECT_PATH.to_string();
|
||||
|
||||
*world.resource_mut::<ProjectSettings>() = default_settings.clone();
|
||||
world.resource_mut::<ProjectSettingsIo>().path = settings_path.clone();
|
||||
world.resource_mut::<ProjectSettingsIo>().dirty = false;
|
||||
|
||||
if let Some(mut workspace) = world.get_resource_mut::<ProjectWorkspace>() {
|
||||
workspace.root = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|p| p.into_os_string().into_string().ok())
|
||||
.unwrap_or_else(|| ".".into());
|
||||
workspace.settings_path = settings_path;
|
||||
workspace.settings_dirty = false;
|
||||
}
|
||||
|
||||
world.resource_mut::<WorkspaceState>().project_name = default_settings.name.clone();
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::New);
|
||||
world.resource_mut::<EditorHistory>().clear();
|
||||
sync_recent_levels_to_scene_io(world);
|
||||
format!("New project: {}", default_settings.name)
|
||||
}
|
||||
|
||||
fn apply_open_project(world: &mut World) -> String {
|
||||
let Some(root) = rfd::FileDialog::new()
|
||||
.set_title("Open Project Folder")
|
||||
.pick_folder()
|
||||
else {
|
||||
return "Open project cancelled".to_string();
|
||||
};
|
||||
|
||||
let settings_path = root.join("assets/project.ron");
|
||||
if !settings_path.exists() {
|
||||
return format!(
|
||||
"No assets/project.ron in {} — pick a project root folder",
|
||||
root.display()
|
||||
);
|
||||
}
|
||||
|
||||
let settings_path_label = settings_path.display().to_string();
|
||||
let settings = load_project_settings_from_path(&settings_path_label);
|
||||
|
||||
*world.resource_mut::<ProjectSettings>() = settings.clone();
|
||||
world.resource_mut::<ProjectSettingsIo>().path = settings_path_label.clone();
|
||||
world.resource_mut::<ProjectSettingsIo>().dirty = false;
|
||||
|
||||
if let Some(mut workspace) = world.get_resource_mut::<ProjectWorkspace>() {
|
||||
workspace.root = root.display().to_string();
|
||||
workspace.settings_path = settings_path_label;
|
||||
workspace.settings_dirty = false;
|
||||
}
|
||||
|
||||
if let Some(mut prefs) = world.get_resource_mut::<UserPreferences>() {
|
||||
push_recent(&mut prefs.recent_projects, workspace_root_label(&root), 8);
|
||||
prefs.last_project_root = Some(root.display().to_string());
|
||||
let _ = crate::project_io::write_user_preferences(&prefs);
|
||||
}
|
||||
|
||||
world.resource_mut::<WorkspaceState>().project_name = settings.name.clone();
|
||||
sync_recent_levels_to_scene_io(world);
|
||||
format!("Opened project: {}", settings.name)
|
||||
}
|
||||
|
||||
fn workspace_root_label(path: &Path) -> String {
|
||||
path.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.map(str::to_string)
|
||||
.unwrap_or_else(|| path.display().to_string())
|
||||
}
|
||||
@@ -3,10 +3,9 @@ use std::path::{Path, PathBuf};
|
||||
use bevy::ecs::entity::EntityHashMap;
|
||||
use bevy::ecs::system::SystemState;
|
||||
use bevy::prelude::*;
|
||||
use bevy::scene::serde::SceneDeserializer;
|
||||
use bevy::scene::DynamicScene;
|
||||
use bevy::scene::DynamicSceneBuilder;
|
||||
use bevy::window::PrimaryWindow;
|
||||
use bevy::world_serialization::serde::WorldDeserializer;
|
||||
use bevy::world_serialization::{DynamicWorld, DynamicWorldBuilder};
|
||||
use scene::{document::SceneDocument, strip_schema_version, validate_level_text};
|
||||
use serde::de::DeserializeSeed;
|
||||
use shared::{
|
||||
@@ -469,42 +468,42 @@ fn save_entities(world: &mut World, path: &Path, entities: Vec<Entity>) -> Resul
|
||||
}
|
||||
}
|
||||
|
||||
let scene = DynamicSceneBuilder::from_world(world)
|
||||
.deny_all()
|
||||
.allow_component::<Name>()
|
||||
.allow_component::<Transform>()
|
||||
.allow_component::<ChildOf>()
|
||||
.allow_component::<LevelObject>()
|
||||
.allow_component::<ActorId>()
|
||||
.allow_component::<ActorName>()
|
||||
.allow_component::<ActorKind>()
|
||||
.allow_component::<InspectorOrder>()
|
||||
.allow_component::<Primitive>()
|
||||
.allow_component::<BrushDesc>()
|
||||
.allow_component::<StaticMeshRenderer>()
|
||||
.allow_component::<MaterialDesc>()
|
||||
.allow_component::<MaterialOverride>()
|
||||
.allow_component::<RigidBodyDesc>()
|
||||
.allow_component::<ColliderDesc>()
|
||||
.allow_component::<PhysicsBody>()
|
||||
.allow_component::<LightDesc>()
|
||||
.allow_component::<PlayerSpawn>()
|
||||
.allow_component::<ModelRef>()
|
||||
.allow_component::<PrefabRef>()
|
||||
.allow_component::<PrefabInstance>()
|
||||
.allow_component::<WeaponSpawn>()
|
||||
.allow_component::<TriggerVolume>()
|
||||
.allow_component::<PostProcessVolumeDesc>()
|
||||
.allow_component::<TeamSpawn>()
|
||||
.allow_component::<ObjectiveMarker>()
|
||||
.allow_component::<HierarchySiblingIndex>()
|
||||
.allow_component::<EditorVisibility>()
|
||||
.extract_entities(entities.into_iter())
|
||||
.remove_empty_entities()
|
||||
.build();
|
||||
|
||||
let ron = {
|
||||
let registry = world.resource::<AppTypeRegistry>().read();
|
||||
let scene = DynamicWorldBuilder::from_world(world, ®istry)
|
||||
.deny_all()
|
||||
.allow_component::<Name>()
|
||||
.allow_component::<Transform>()
|
||||
.allow_component::<ChildOf>()
|
||||
.allow_component::<LevelObject>()
|
||||
.allow_component::<ActorId>()
|
||||
.allow_component::<ActorName>()
|
||||
.allow_component::<ActorKind>()
|
||||
.allow_component::<InspectorOrder>()
|
||||
.allow_component::<Primitive>()
|
||||
.allow_component::<BrushDesc>()
|
||||
.allow_component::<StaticMeshRenderer>()
|
||||
.allow_component::<MaterialDesc>()
|
||||
.allow_component::<MaterialOverride>()
|
||||
.allow_component::<RigidBodyDesc>()
|
||||
.allow_component::<ColliderDesc>()
|
||||
.allow_component::<PhysicsBody>()
|
||||
.allow_component::<LightDesc>()
|
||||
.allow_component::<PlayerSpawn>()
|
||||
.allow_component::<ModelRef>()
|
||||
.allow_component::<PrefabRef>()
|
||||
.allow_component::<PrefabInstance>()
|
||||
.allow_component::<WeaponSpawn>()
|
||||
.allow_component::<TriggerVolume>()
|
||||
.allow_component::<PostProcessVolumeDesc>()
|
||||
.allow_component::<TeamSpawn>()
|
||||
.allow_component::<ObjectiveMarker>()
|
||||
.allow_component::<HierarchySiblingIndex>()
|
||||
.allow_component::<EditorVisibility>()
|
||||
.extract_entities(entities.into_iter())
|
||||
.remove_empty_entities()
|
||||
.build();
|
||||
|
||||
scene
|
||||
.serialize(®istry)
|
||||
.map_err(|err| format!("could not serialize scene: {err}"))?
|
||||
@@ -536,10 +535,12 @@ fn load_level(world: &mut World, path: &Path) -> Result<(), String> {
|
||||
clear_loaded_scene_roots(world);
|
||||
clear_level_objects(world);
|
||||
|
||||
let dynamic_scene: DynamicScene = {
|
||||
let dynamic_scene: DynamicWorld = {
|
||||
let registry = world.resource::<AppTypeRegistry>().read();
|
||||
let scene_deserializer = SceneDeserializer {
|
||||
let mut asset_server = world.resource::<AssetServer>().clone();
|
||||
let scene_deserializer = WorldDeserializer {
|
||||
type_registry: ®istry,
|
||||
load_from_path: &mut asset_server,
|
||||
};
|
||||
let mut deserializer =
|
||||
ron::de::Deserializer::from_str(&bevy_ron).map_err(|err| err.to_string())?;
|
||||
@@ -590,7 +591,9 @@ fn finalize_scene_load(world: &mut World) {
|
||||
)> = SystemState::new(world);
|
||||
|
||||
{
|
||||
let (settings, scene_suns, project_suns) = state.get_mut(world);
|
||||
let (settings, scene_suns, project_suns) = state
|
||||
.get_mut(world)
|
||||
.expect("finalize_scene_load system params should be valid");
|
||||
game_hot::sync_project_sun_from_settings(settings, scene_suns, project_suns);
|
||||
}
|
||||
state.apply(world);
|
||||
|
||||
@@ -897,6 +897,10 @@ fn visible_assets(
|
||||
rows
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset grid rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_grid(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -1169,6 +1173,10 @@ fn prefetch_embedded_thumbnails(
|
||||
});
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "embedded asset rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn draw_embedded_asset_cell(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Dock tab open/focus helpers and default panel node placement.
|
||||
|
||||
use egui_dock::{DockState, Node, NodeIndex, SurfaceIndex, TabIndex, Tree};
|
||||
use egui_dock::{DockState, Node, NodeIndex, NodePath, SurfaceIndex, TabIndex, TabPath, Tree};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::EditorTab;
|
||||
@@ -43,15 +43,15 @@ impl PanelNodes {
|
||||
/// Scan the main surface for open tabs and refresh node indices (handles user drag/split).
|
||||
pub fn discover(dock: &DockState<EditorTab>, fallback: Self) -> Self {
|
||||
let mut nodes = fallback;
|
||||
for ((surface, node_idx), tab) in dock.iter_all_tabs() {
|
||||
if surface != SurfaceIndex::main() {
|
||||
for (path, tab) in dock.iter_all_tabs() {
|
||||
if path.surface != SurfaceIndex::main() {
|
||||
continue;
|
||||
}
|
||||
match tab {
|
||||
EditorTab::Viewport | EditorTab::GameView => nodes.main_view = node_idx.0,
|
||||
EditorTab::Hierarchy => nodes.hierarchy = node_idx.0,
|
||||
EditorTab::Inspector => nodes.inspector = node_idx.0,
|
||||
EditorTab::AssetBrowser | EditorTab::Toolbar => nodes.bottom = node_idx.0,
|
||||
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::Toolbar => nodes.bottom = path.node.0,
|
||||
}
|
||||
}
|
||||
nodes
|
||||
@@ -93,8 +93,9 @@ pub fn open_and_focus_tab(
|
||||
let tab_idx = push_tab_to_node(tree, node, tab);
|
||||
(node, tab_idx)
|
||||
};
|
||||
dock.set_active_tab((SurfaceIndex::main(), node, tab_idx));
|
||||
dock.set_focused_node_and_surface((SurfaceIndex::main(), node));
|
||||
let node_path = NodePath::new(SurfaceIndex::main(), node);
|
||||
let _ = dock.set_active_tab(TabPath::new(SurfaceIndex::main(), node, tab_idx));
|
||||
dock.set_focused_node_and_surface(node_path);
|
||||
(node, tab_idx)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,5 +17,26 @@ fn configure_editor_fonts(mut contexts: Query<&mut EguiContext, Added<PrimaryEgu
|
||||
};
|
||||
let mut fonts = bevy_egui::egui::FontDefinitions::default();
|
||||
egui_phosphor_icons::add_fonts(&mut fonts);
|
||||
|
||||
// Phosphor families contain icon glyphs only. Text fallbacks give egui a
|
||||
// replacement glyph for malformed/missing icons without changing icon lookup.
|
||||
let text_fallbacks = fonts
|
||||
.families
|
||||
.get(&bevy_egui::egui::FontFamily::Proportional)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
for (family, font_names) in &mut fonts.families {
|
||||
let bevy_egui::egui::FontFamily::Name(name) = family else {
|
||||
continue;
|
||||
};
|
||||
if !name.starts_with("phosphor-") {
|
||||
continue;
|
||||
}
|
||||
for fallback in &text_fallbacks {
|
||||
if !font_names.contains(fallback) {
|
||||
font_names.push(fallback.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.get_mut().set_fonts(fonts);
|
||||
}
|
||||
@@ -20,10 +20,10 @@ use crate::ui::helpers::{
|
||||
use crate::ui::hierarchy_ops::{
|
||||
authored_children, editor_visibility, entity_hierarchy_path, entity_matches_filter,
|
||||
hierarchy_label_for_entity, is_entity_locked, level_object_roots, sort_siblings,
|
||||
would_create_cycle,
|
||||
would_create_cycle, HierarchyLabel,
|
||||
};
|
||||
use crate::ui::hierarchy_state::{HierarchyPanelState, HierarchySort};
|
||||
use crate::ui::theme::panel_heading;
|
||||
use crate::ui::theme::{panel_heading, TEXT, TEXT_DIM, TEXT_SELECTED};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HierarchyDragPayload {
|
||||
@@ -138,6 +138,7 @@ pub fn hierarchy_panel_ui(
|
||||
.is_some();
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("hierarchy_tree")
|
||||
.scroll_source(ScrollSource {
|
||||
scroll_bar: true,
|
||||
drag: !dragging,
|
||||
@@ -230,6 +231,10 @@ fn draw_root_drop_zone(ui: &mut egui::Ui, drop_target: &mut Option<DropTarget>)
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "recursive hierarchy rendering threads interaction state explicitly"
|
||||
)]
|
||||
fn draw_authored_node(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -278,7 +283,7 @@ fn draw_authored_node(
|
||||
} else {
|
||||
icons::CARET_RIGHT
|
||||
};
|
||||
if ui.small_button(twistie.as_str()).clicked() {
|
||||
if ui.small_button(twistie.regular()).clicked() {
|
||||
let path = path.clone();
|
||||
let expanding = !world
|
||||
.resource::<HierarchyPanelState>()
|
||||
@@ -353,7 +358,8 @@ fn draw_authored_node(
|
||||
} else {
|
||||
let selected = selected_entities.contains(entity);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Authored);
|
||||
let response = ui.selectable_label(selected, label);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
if response.clicked() && !is_locked {
|
||||
let additive = ui.input(|input| {
|
||||
input.modifiers.shift || input.modifiers.command || input.modifiers.ctrl
|
||||
@@ -512,7 +518,7 @@ fn draw_generated_node(
|
||||
} else {
|
||||
icons::CARET_RIGHT
|
||||
};
|
||||
if ui.small_button(twistie.as_str()).clicked() {
|
||||
if ui.small_button(twistie.regular()).clicked() {
|
||||
is_expanded = !is_expanded;
|
||||
}
|
||||
} else {
|
||||
@@ -520,14 +526,10 @@ fn draw_generated_node(
|
||||
}
|
||||
ui.add_enabled(
|
||||
false,
|
||||
egui::Label::new(
|
||||
egui::RichText::new(hierarchy_label_for_entity(
|
||||
world,
|
||||
entity,
|
||||
HierarchyNodeKind::Generated,
|
||||
))
|
||||
.weak(),
|
||||
),
|
||||
egui::Label::new(hierarchy_label_text(
|
||||
hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Generated),
|
||||
TEXT_DIM,
|
||||
)),
|
||||
);
|
||||
});
|
||||
if !is_expanded {
|
||||
@@ -555,7 +557,9 @@ fn draw_runtime_node(
|
||||
ui.add_space(depth as f32 * 14.0);
|
||||
ui.add_space(18.0);
|
||||
let label = hierarchy_label_for_entity(world, entity, HierarchyNodeKind::Runtime);
|
||||
let response = ui.selectable_label(selected_entities.contains(entity), label);
|
||||
let selected = selected_entities.contains(entity);
|
||||
let color = if selected { TEXT_SELECTED } else { TEXT_DIM };
|
||||
let response = ui.selectable_label(selected, hierarchy_label_text(label, color));
|
||||
if response.clicked() {
|
||||
selected_entities.select_replace(entity);
|
||||
}
|
||||
@@ -575,6 +579,29 @@ fn draw_runtime_node(
|
||||
}
|
||||
}
|
||||
|
||||
fn hierarchy_label_text(label: HierarchyLabel, color: egui::Color32) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(
|
||||
label.icon,
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Name("phosphor-regular".into())),
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.append(
|
||||
&format!(" {}", label.text),
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Proportional),
|
||||
color,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.into()
|
||||
}
|
||||
|
||||
fn authored_context_menu(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -596,15 +623,16 @@ fn authored_context_menu(
|
||||
delete_entities_with_history(world, &[entity]);
|
||||
ui.close();
|
||||
}
|
||||
if selected_entities.len() >= 2 && selected_entities.contains(entity) {
|
||||
if ui.button("Group").clicked() {
|
||||
let entities: Vec<Entity> = selected_entities
|
||||
.iter()
|
||||
.filter(|e| is_level_object(world, *e))
|
||||
.collect();
|
||||
group_selection_with_history(world, &entities);
|
||||
ui.close();
|
||||
}
|
||||
if selected_entities.len() >= 2
|
||||
&& selected_entities.contains(entity)
|
||||
&& ui.button("Group").clicked()
|
||||
{
|
||||
let entities: Vec<Entity> = selected_entities
|
||||
.iter()
|
||||
.filter(|e| is_level_object(world, *e))
|
||||
.collect();
|
||||
group_selection_with_history(world, &entities);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button("Unparent").clicked() {
|
||||
reparent_with_history(world, entity, None);
|
||||
@@ -701,7 +729,7 @@ pub(crate) fn is_hierarchy_generated_child(world: &World, entity: Entity) -> boo
|
||||
&& (entity_ref.contains::<Transform>() || entity_ref.contains::<GlobalTransform>())
|
||||
&& (entity_ref.contains::<Name>()
|
||||
|| entity_ref.contains::<Mesh3d>()
|
||||
|| entity_ref.contains::<SceneRoot>())
|
||||
|| entity_ref.contains::<WorldAssetRoot>())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -350,11 +350,16 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HierarchyLabel {
|
||||
pub icon: &'static str,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
pub fn hierarchy_label_for_entity(
|
||||
world: &World,
|
||||
entity: Entity,
|
||||
kind: HierarchyNodeKind,
|
||||
) -> String {
|
||||
) -> HierarchyLabel {
|
||||
use egui_phosphor_icons::icons;
|
||||
let icon = world
|
||||
.get::<ActorKind>(entity)
|
||||
@@ -365,18 +370,18 @@ pub fn hierarchy_label_for_entity(
|
||||
HierarchyNodeKind::Generated => icons::STACK.as_str(),
|
||||
HierarchyNodeKind::Runtime => icons::CPU.as_str(),
|
||||
});
|
||||
let mut label = format!("{} {}", icon, entity_name(world, entity));
|
||||
let mut text = entity_name(world, entity);
|
||||
if let Some(light) = world.get::<LightDesc>(entity) {
|
||||
if matches!(light.kind, AuthoringLightKind::Directional) {
|
||||
label.push_str(" ☀");
|
||||
text.push_str(" (sun)");
|
||||
}
|
||||
}
|
||||
match kind {
|
||||
HierarchyNodeKind::Authored => {}
|
||||
HierarchyNodeKind::Generated => label.push_str(" (generated)"),
|
||||
HierarchyNodeKind::Runtime => label.push_str(" (runtime)"),
|
||||
HierarchyNodeKind::Generated => text.push_str(" (generated)"),
|
||||
HierarchyNodeKind::Runtime => text.push_str(" (runtime)"),
|
||||
}
|
||||
label
|
||||
HierarchyLabel { icon, text }
|
||||
}
|
||||
|
||||
pub fn entity_matches_filter(world: &World, entity: Entity, filter_lower: &str) -> bool {
|
||||
|
||||
@@ -48,12 +48,13 @@ impl Default for HierarchyPanelState {
|
||||
|
||||
impl HierarchyPanelState {
|
||||
pub fn from_prefs(prefs: &UserPreferences) -> Self {
|
||||
let mut state = Self::default();
|
||||
state.filter = prefs.hierarchy_filter.clone();
|
||||
state.show_generated = prefs.hierarchy_show_generated;
|
||||
state.show_runtime = prefs.hierarchy_show_runtime;
|
||||
state.sort_mode = prefs.hierarchy_sort_mode;
|
||||
state
|
||||
Self {
|
||||
filter: prefs.hierarchy_filter.clone(),
|
||||
show_generated: prefs.hierarchy_show_generated,
|
||||
show_runtime: prefs.hierarchy_show_runtime,
|
||||
sort_mode: prefs.hierarchy_sort_mode,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_dirty(&mut self) {
|
||||
|
||||
@@ -764,7 +764,7 @@ fn add_component_picker_shelf(
|
||||
target: Entity,
|
||||
anchor: egui::Rect,
|
||||
) {
|
||||
if !world.get_entity(target).is_ok() {
|
||||
if world.get_entity(target).is_err() {
|
||||
if let Some(mut state) = world.get_resource_mut::<InspectorPanelState>() {
|
||||
state.add_component_open = false;
|
||||
state.add_component_target = None;
|
||||
@@ -777,7 +777,7 @@ fn add_component_picker_shelf(
|
||||
.descriptors
|
||||
.clone();
|
||||
|
||||
let visible = ui.clip_rect().intersect(ui.ctx().available_rect());
|
||||
let visible = ui.clip_rect().intersect(ui.ctx().content_rect());
|
||||
let space_above = (anchor.min.y - visible.top()).max(0.0);
|
||||
let space_below = (visible.bottom() - anchor.max.y).max(0.0);
|
||||
let direction = if space_below >= space_above {
|
||||
@@ -865,7 +865,7 @@ fn add_component_picker_shelf_contents(
|
||||
}
|
||||
|
||||
let search = search_input.to_lowercase();
|
||||
let filtered = filtered_component_descriptors(&descriptors, &search);
|
||||
let filtered = filtered_component_descriptors(descriptors, &search);
|
||||
{
|
||||
let mut state = world.resource_mut::<InspectorPanelState>();
|
||||
if !filtered.is_empty() {
|
||||
@@ -905,7 +905,7 @@ fn add_component_picker_shelf_contents(
|
||||
.resource::<InspectorPanelState>()
|
||||
.add_component_selected_index;
|
||||
if let Some(descriptor) = filtered.get(selected_index) {
|
||||
let add_state = component_add_state(world, target, descriptor, &descriptors);
|
||||
let add_state = component_add_state(world, target, descriptor, descriptors);
|
||||
if add_state.addable {
|
||||
insert_registered_component(world, target, descriptor.type_name);
|
||||
let mut state = world.resource_mut::<InspectorPanelState>();
|
||||
@@ -941,8 +941,7 @@ fn add_component_picker_shelf_contents(
|
||||
last_category = Some(descriptor.category);
|
||||
}
|
||||
|
||||
let add_state =
|
||||
component_add_state(world, target, descriptor, &descriptors);
|
||||
let add_state = component_add_state(world, target, descriptor, descriptors);
|
||||
let selected = index == selected_index;
|
||||
let row = ui
|
||||
.horizontal(|ui| {
|
||||
@@ -1893,8 +1892,10 @@ fn static_mesh_renderer_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity)
|
||||
.clicked();
|
||||
if add_slot {
|
||||
let index = renderer.slots.len();
|
||||
let mut entry = StaticMeshRendererEntry::default();
|
||||
entry.id = ComponentInstanceId::new(format!("slot:{index}"));
|
||||
let entry = StaticMeshRendererEntry {
|
||||
id: ComponentInstanceId::new(format!("slot:{index}")),
|
||||
..Default::default()
|
||||
};
|
||||
renderer.slots.push(entry);
|
||||
changed = true;
|
||||
}
|
||||
@@ -2026,6 +2027,10 @@ fn thumbnail_for_mesh(
|
||||
.and_then(|candidate| candidate.texture_id)
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset selector rows keep immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_selector_row(
|
||||
ui: &mut egui::Ui,
|
||||
label: &str,
|
||||
@@ -2075,6 +2080,10 @@ fn asset_selector_row(
|
||||
response
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "asset selector controls keep immediate-mode UI inputs explicit"
|
||||
)]
|
||||
fn asset_selector_control(
|
||||
ui: &mut egui::Ui,
|
||||
icon: Icon,
|
||||
|
||||
@@ -9,7 +9,6 @@ use crate::history::{apply_command_redo, apply_command_undo, EditorHistory};
|
||||
use crate::scene_io::{SceneIo, SceneIoRequest};
|
||||
use crate::settings_ui::{open_project_settings_panel, ProjectSettingsPanel};
|
||||
use crate::state::{EditorMode, PlayPaused};
|
||||
use crate::workspace::{request_new_project, request_open_project};
|
||||
|
||||
use super::diagnostics::{BrushDiagnosticsPanel, DiagnosticsPanel};
|
||||
use super::dock_tabs::{open_and_focus_tab, tab_is_open, tab_label, PanelNodes, PANEL_TABS};
|
||||
@@ -22,25 +21,14 @@ use super::EditorTab;
|
||||
|
||||
pub fn top_menu_bar(
|
||||
world: &mut World,
|
||||
ctx: &egui::Context,
|
||||
root_ui: &mut egui::Ui,
|
||||
selected: &SelectedEntities,
|
||||
dock_state: &mut DockState<EditorTab>,
|
||||
panel_nodes: &mut PanelNodes,
|
||||
) {
|
||||
egui::TopBottomPanel::top("editor_menu_bar").show(ctx, |ui| {
|
||||
egui::Panel::top("editor_menu_bar").show_inside(root_ui, |ui| {
|
||||
egui::MenuBar::new().ui(ui, |ui| {
|
||||
ui.menu_button("File", |ui| {
|
||||
ui.menu_button("Project", |ui| {
|
||||
if menu_item(ui, "New Project", None, true).clicked() {
|
||||
request_new_project(world);
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Open Project...", None, true).clicked() {
|
||||
request_open_project(world);
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
if menu_item(ui, "New Scene", None, true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::New);
|
||||
ui.close();
|
||||
|
||||
+32
-26
@@ -66,7 +66,7 @@ pub struct UiState {
|
||||
}
|
||||
|
||||
pub fn egui_captures_keyboard(ctx: &egui::Context) -> bool {
|
||||
ctx.wants_keyboard_input()
|
||||
ctx.egui_wants_keyboard_input()
|
||||
}
|
||||
|
||||
pub fn egui_captures_keyboard_from_world(world: &mut World) -> bool {
|
||||
@@ -118,6 +118,10 @@ impl UiState {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
deprecated,
|
||||
reason = "bevy_egui exposes a Context during EguiPrimaryContextPass, so one top-level panel must bridge to the new Ui-based panel API"
|
||||
)]
|
||||
fn ui(&mut self, world: &mut World, ctx: &mut egui::Context, dt: f32) {
|
||||
apply_editor_theme(ctx);
|
||||
|
||||
@@ -129,17 +133,6 @@ impl UiState {
|
||||
}
|
||||
}
|
||||
|
||||
top_menu_bar(
|
||||
world,
|
||||
ctx,
|
||||
&self.selected_entities,
|
||||
&mut self.dock_state,
|
||||
&mut self.panel_nodes,
|
||||
);
|
||||
|
||||
editor_toolbar_panel(world, ctx);
|
||||
status_bar_ui(world, ctx, &self.selected_entities, mode);
|
||||
|
||||
self.pointer_in_viewport = false;
|
||||
self.viewport_pointer_pos = None;
|
||||
|
||||
@@ -154,21 +147,34 @@ impl UiState {
|
||||
});
|
||||
}
|
||||
|
||||
let mut viewer = TabViewer {
|
||||
world,
|
||||
viewport_rect: &mut self.viewport_rect,
|
||||
pointer_in_viewport: &mut self.pointer_in_viewport,
|
||||
viewport_pointer_pos: &mut self.viewport_pointer_pos,
|
||||
playing,
|
||||
cursor_grabbed,
|
||||
selected_entities: &mut self.selected_entities,
|
||||
renaming_entity: &mut self.renaming_entity,
|
||||
rename_buffer: &mut self.rename_buffer,
|
||||
};
|
||||
egui::CentralPanel::no_frame().show(ctx, |root_ui| {
|
||||
top_menu_bar(
|
||||
world,
|
||||
root_ui,
|
||||
&self.selected_entities,
|
||||
&mut self.dock_state,
|
||||
&mut self.panel_nodes,
|
||||
);
|
||||
|
||||
DockArea::new(&mut self.dock_state)
|
||||
.style(editor_dock_style(ctx))
|
||||
.show(ctx, &mut viewer);
|
||||
editor_toolbar_panel(world, root_ui);
|
||||
status_bar_ui(world, root_ui, &self.selected_entities, mode);
|
||||
|
||||
let mut viewer = TabViewer {
|
||||
world,
|
||||
viewport_rect: &mut self.viewport_rect,
|
||||
pointer_in_viewport: &mut self.pointer_in_viewport,
|
||||
viewport_pointer_pos: &mut self.viewport_pointer_pos,
|
||||
playing,
|
||||
cursor_grabbed,
|
||||
selected_entities: &mut self.selected_entities,
|
||||
renaming_entity: &mut self.renaming_entity,
|
||||
rename_buffer: &mut self.rename_buffer,
|
||||
};
|
||||
|
||||
DockArea::new(&mut self.dock_state)
|
||||
.style(editor_dock_style(ctx))
|
||||
.show_inside(root_ui, &mut viewer);
|
||||
});
|
||||
|
||||
self.panel_nodes = PanelNodes::discover(&self.dock_state, self.panel_nodes);
|
||||
|
||||
|
||||
@@ -13,59 +13,87 @@ use super::theme::{status_bar_frame, TEXT};
|
||||
|
||||
pub fn status_bar_ui(
|
||||
world: &World,
|
||||
ctx: &egui::Context,
|
||||
root_ui: &mut egui::Ui,
|
||||
selected: &SelectedEntities,
|
||||
mode: EditorMode,
|
||||
) {
|
||||
egui::TopBottomPanel::bottom("editor_status_bar")
|
||||
.exact_height(24.0)
|
||||
egui::Panel::bottom("editor_status_bar")
|
||||
.exact_size(24.0)
|
||||
.frame(status_bar_frame())
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 16.0;
|
||||
ui.label(egui::RichText::new(scene_line(world)).color(TEXT));
|
||||
.show_inside(root_ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.x = 12.0;
|
||||
egui::containers::Sides::new()
|
||||
.shrink_left()
|
||||
.truncate()
|
||||
.show(
|
||||
ui,
|
||||
|ui| {
|
||||
let status = primary_status_line(world);
|
||||
ui.add(
|
||||
egui::Label::new(egui::RichText::new(&status).color(TEXT)).truncate(),
|
||||
)
|
||||
.on_hover_text(status);
|
||||
},
|
||||
|ui| {
|
||||
let mode_label = match mode {
|
||||
EditorMode::Editing => "Edit".to_string(),
|
||||
EditorMode::Playing => {
|
||||
if world.resource::<PlayPaused>().0 {
|
||||
"Play (paused)".to_string()
|
||||
} else {
|
||||
"Play".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(egui::RichText::new(mode_label).color(TEXT));
|
||||
|
||||
let mode_label = match mode {
|
||||
EditorMode::Editing => "Edit".to_string(),
|
||||
EditorMode::Playing => {
|
||||
if world.resource::<PlayPaused>().0 {
|
||||
"Play (paused)".to_string()
|
||||
} else {
|
||||
"Play".to_string()
|
||||
let count = selected.len();
|
||||
let selection = match count {
|
||||
0 => "None".to_string(),
|
||||
1 => "1 selected".to_string(),
|
||||
_ => format!("{count} selected"),
|
||||
};
|
||||
ui.label(egui::RichText::new(selection).color(TEXT));
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(world.resource::<EditorHistory>().status.clone())
|
||||
.color(TEXT),
|
||||
);
|
||||
|
||||
if let Some(operator_label) = world.resource::<ActiveOperator>().label() {
|
||||
ui.label(egui::RichText::new(operator_label).color(TEXT));
|
||||
}
|
||||
}
|
||||
};
|
||||
ui.label(egui::RichText::new(mode_label).color(TEXT));
|
||||
|
||||
let count = selected.len();
|
||||
let sel = if count == 0 {
|
||||
"None".to_string()
|
||||
} else if count == 1 {
|
||||
"1 selected".to_string()
|
||||
} else {
|
||||
format!("{count} selected")
|
||||
};
|
||||
ui.label(egui::RichText::new(sel).color(TEXT));
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(world.resource::<EditorHistory>().status.clone())
|
||||
.color(TEXT),
|
||||
#[cfg(feature = "hot-reload")]
|
||||
if let Some(hot) = world.get_resource::<crate::hot_reload::HotReloadState>()
|
||||
{
|
||||
ui.label(egui::RichText::new(hot.label.clone()).color(TEXT));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if let Some(operator_label) = world.resource::<ActiveOperator>().label() {
|
||||
ui.label(egui::RichText::new(operator_label).color(TEXT));
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot-reload")]
|
||||
if let Some(hot) = world.get_resource::<crate::hot_reload::HotReloadState>() {
|
||||
ui.label(egui::RichText::new(hot.label.clone()).color(TEXT));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_line(world: &World) -> String {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
fn scene_line(scene_io: &SceneIo) -> String {
|
||||
let dirty = if scene_io.dirty { " *" } else { "" };
|
||||
format!("Scene: {}{dirty}", scene_io.active_path_label())
|
||||
}
|
||||
|
||||
fn primary_status_line(world: &World) -> String {
|
||||
let scene_io = world.resource::<SceneIo>();
|
||||
format!("{} | {}", scene_io.status, scene_line(scene_io))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn scene_line_marks_unsaved_changes() {
|
||||
let mut scene_io = SceneIo::default();
|
||||
assert!(!scene_line(&scene_io).ends_with('*'));
|
||||
|
||||
scene_io.mark_dirty();
|
||||
assert!(scene_line(&scene_io).ends_with('*'));
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
visuals.window_stroke = Stroke::new(1.0, BORDER);
|
||||
visuals.window_corner_radius = CornerRadius::same(4);
|
||||
|
||||
let mut style = (*ctx.style()).clone();
|
||||
let mut style = (*ctx.global_style()).clone();
|
||||
style.visuals = visuals;
|
||||
style.spacing.item_spacing = egui::vec2(8.0, 6.0);
|
||||
style.spacing.button_padding = egui::vec2(8.0, 4.0);
|
||||
@@ -69,11 +69,11 @@ pub fn apply_editor_theme(ctx: &egui::Context) {
|
||||
egui::TextStyle::Heading,
|
||||
FontId::new(15.0, egui::FontFamily::Proportional),
|
||||
);
|
||||
ctx.set_style(style);
|
||||
ctx.set_global_style(style);
|
||||
}
|
||||
|
||||
pub fn editor_dock_style(ctx: &egui::Context) -> DockStyle {
|
||||
let mut style = DockStyle::from_egui(ctx.style().as_ref());
|
||||
let mut style = DockStyle::from_egui(ctx.global_style().as_ref());
|
||||
style.dock_area_padding = Some(egui::Margin::same(2));
|
||||
style.main_surface_border_stroke = Stroke::new(1.0, BORDER);
|
||||
style.separator.width = 2.0;
|
||||
|
||||
@@ -19,11 +19,13 @@ use super::widgets::{icon_button, panel_toolbar_row, toolbar_separator, transpor
|
||||
|
||||
/// Toolbar strip height (menu bar is separate).
|
||||
const TOOLBAR_HEIGHT: f32 = 56.0;
|
||||
const TRANSPORT_WIDTH: f32 = 152.0;
|
||||
const TRANSPORT_SLOT_STEP: f32 = 54.0;
|
||||
|
||||
pub fn editor_toolbar_panel(world: &mut World, ctx: &egui::Context) {
|
||||
egui::TopBottomPanel::top("editor_toolbar")
|
||||
.exact_height(TOOLBAR_HEIGHT)
|
||||
.show(ctx, |ui| {
|
||||
pub fn editor_toolbar_panel(world: &mut World, root_ui: &mut egui::Ui) {
|
||||
egui::Panel::top("editor_toolbar")
|
||||
.exact_size(TOOLBAR_HEIGHT)
|
||||
.show_inside(root_ui, |ui| {
|
||||
toolbar_ui(world, ui);
|
||||
});
|
||||
}
|
||||
@@ -41,7 +43,7 @@ pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
);
|
||||
let transport_rect = egui::Rect::from_center_size(
|
||||
egui::pos2(toolbar_rect.center().x, center_y),
|
||||
egui::vec2(transport_width(world), 44.0),
|
||||
egui::vec2(TRANSPORT_WIDTH, 44.0),
|
||||
);
|
||||
|
||||
let mut left_ui = ui.new_child(
|
||||
@@ -63,16 +65,6 @@ pub fn toolbar_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
transport_controls(world, &mut transport_ui);
|
||||
}
|
||||
|
||||
fn transport_width(world: &World) -> f32 {
|
||||
let button_count = match *world.resource::<State<EditorMode>>().get() {
|
||||
EditorMode::Editing => 1.0,
|
||||
EditorMode::Playing => 3.0,
|
||||
};
|
||||
let gap_count = button_count - 1.0;
|
||||
|
||||
button_count * 44.0 + gap_count * 10.0
|
||||
}
|
||||
|
||||
fn left_toolbar(world: &mut World, ui: &mut egui::Ui) {
|
||||
panel_toolbar_row(ui, |ui| {
|
||||
if icon_button(ui, icons::CUBE, "Spawn cube").clicked() {
|
||||
@@ -113,7 +105,13 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
let mode = *world.resource::<State<EditorMode>>().get();
|
||||
match mode {
|
||||
EditorMode::Editing => {
|
||||
if transport_button_large(ui, icons::PLAY, "Play (F5)", true).clicked() {
|
||||
ui.add_space(TRANSPORT_SLOT_STEP);
|
||||
let play_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::PLAY, "Play (F5)", true).clicked()
|
||||
})
|
||||
.inner;
|
||||
if play_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
}
|
||||
@@ -125,12 +123,21 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
} else {
|
||||
"Pause simulation (F6)"
|
||||
};
|
||||
if transport_button_large(ui, pause_icon, pause_tip, false).clicked() {
|
||||
let pause_clicked = ui
|
||||
.push_id("transport_left", |ui| {
|
||||
transport_button_large(ui, pause_icon, pause_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
if pause_clicked {
|
||||
toggle_play_paused(world);
|
||||
}
|
||||
if transport_button_large(ui, icons::STOP, "Stop and return to Edit (F5)", false)
|
||||
.clicked()
|
||||
{
|
||||
let stop_clicked = ui
|
||||
.push_id("transport_center", |ui| {
|
||||
transport_button_large(ui, icons::STOP, "Stop and return to Edit (F5)", false)
|
||||
.clicked()
|
||||
})
|
||||
.inner;
|
||||
if stop_clicked {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
|
||||
@@ -139,7 +146,12 @@ fn transport_controls(world: &mut World, ui: &mut egui::Ui) {
|
||||
PlayPossession::Possessed => (icons::SIGN_OUT, "Eject from player (F8)"),
|
||||
PlayPossession::Ejected => (icons::USER, "Possess player (F8)"),
|
||||
};
|
||||
if transport_button_large(ui, eject_icon, eject_tip, false).clicked() {
|
||||
let possession_clicked = ui
|
||||
.push_id("transport_right", |ui| {
|
||||
transport_button_large(ui, eject_icon, eject_tip, false).clicked()
|
||||
})
|
||||
.inner;
|
||||
if possession_clicked {
|
||||
toggle_possession(world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::render_target::ViewportRenderTarget;
|
||||
use crate::selection::ViewportClick;
|
||||
use crate::state::PlayPossession;
|
||||
use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::BrushEditMode;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
use crate::viewport::brush_tool::{BrushToolPhase, BrushToolState};
|
||||
use crate::viewport::{
|
||||
snap_translation, viewport_ground_position, EditorViewportMode, ViewportDisplayMode,
|
||||
@@ -36,6 +36,10 @@ pub struct ViewportUiState {
|
||||
|
||||
const VIEWPORT_TOOLTIP: &str = "RMB + WASD/QE: fly | MMB: pan | Scroll: dolly\nW/E/R: gizmo | X: world/local | F: focus | G: game view | Ctrl+G: grid\nTab: cycle overlapping picks | Play/Pause/Stop: main toolbar (F5 / F6)";
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "viewport tab rendering keeps immediate-mode UI inputs explicit"
|
||||
)]
|
||||
pub fn viewport_tab_ui(
|
||||
world: &mut World,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -161,20 +165,58 @@ fn scene_view_brush_mode_badge(world: &World, ctx: &egui::Context, scene_rect: e
|
||||
if !mode.is_element_mode() {
|
||||
return;
|
||||
}
|
||||
let selected_count = world
|
||||
.get_resource::<BrushElementSelection>()
|
||||
.map(|selection| selection.elements.len())
|
||||
.unwrap_or(0);
|
||||
egui::Area::new(egui::Id::new("scene_view_brush_mode_badge"))
|
||||
.fixed_pos(scene_rect.right_bottom() + egui::vec2(-150.0, -22.0))
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
egui::Frame::new()
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(35, 44, 50, 220))
|
||||
.corner_radius(egui::CornerRadius::same(3))
|
||||
.inner_margin(egui::Margin::symmetric(6, 2))
|
||||
.fill(egui::Color32::from_rgba_unmultiplied(20, 18, 28, 230))
|
||||
.stroke(egui::Stroke::new(
|
||||
1.0,
|
||||
egui::Color32::from_rgba_unmultiplied(210, 140, 255, 210),
|
||||
))
|
||||
.corner_radius(egui::CornerRadius::same(4))
|
||||
.inner_margin(egui::Margin::symmetric(8, 6))
|
||||
.show(ui, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush: {}", mode.label()))
|
||||
.color(egui::Color32::from_rgb(170, 220, 255))
|
||||
.small(),
|
||||
);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Brush {}", mode.label()))
|
||||
.color(egui::Color32::from_rgb(230, 190, 255))
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{selected_count} selected"))
|
||||
.color(egui::Color32::from_rgb(205, 200, 215))
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new("Element gizmo")
|
||||
.color(egui::Color32::from_rgb(255, 190, 120))
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
match mode {
|
||||
BrushEditMode::Vertex => key_hint(ui, "LMB", "Select vertex"),
|
||||
BrushEditMode::Edge => key_hint(ui, "LMB", "Select edge"),
|
||||
BrushEditMode::Face => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Clip => key_hint(ui, "LMB", "Select face"),
|
||||
BrushEditMode::Object => {}
|
||||
}
|
||||
if !matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "W/E/R", "Move/rotate/scale");
|
||||
}
|
||||
if matches!(mode, BrushEditMode::Clip) {
|
||||
key_hint(ui, "Enter", "Clip");
|
||||
}
|
||||
key_hint(ui, "Shift+LMB", "Multi");
|
||||
key_hint(ui, "Esc", "Object");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ impl Material for ActorIconOverlayMaterial {
|
||||
) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
||||
descriptor.primitive.cull_mode = None;
|
||||
if let Some(depth) = &mut descriptor.depth_stencil {
|
||||
depth.depth_write_enabled = false;
|
||||
depth.depth_compare = CompareFunction::Always;
|
||||
depth.depth_write_enabled = Some(false);
|
||||
depth.depth_compare = Some(CompareFunction::Always);
|
||||
}
|
||||
if let Some(fragment) = &mut descriptor.fragment {
|
||||
if let Some(target) = fragment
|
||||
|
||||
@@ -9,12 +9,14 @@ use shared::{
|
||||
|
||||
use crate::camera::EditorCamera;
|
||||
use crate::history::{push_command, set_brush_transform_with_history, EditorCommand};
|
||||
use crate::infra::EditorOnly;
|
||||
use crate::operators::{ActiveOperator, OperatorPhase, OperatorStatus};
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::selection::ViewportClick;
|
||||
use crate::state::scene_tools_active;
|
||||
use crate::ui::{viewport_keyboard_shortcuts_active, UiState};
|
||||
use crate::viewport::{scene_view_ray, ViewportDisplayMode};
|
||||
use transform_gizmo_bevy::prelude::GizmoTarget;
|
||||
|
||||
#[derive(Resource, Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub enum BrushEditMode {
|
||||
@@ -98,27 +100,33 @@ impl Plugin for BrushEditPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<BrushEditMode>()
|
||||
.init_resource::<BrushElementSelection>()
|
||||
.init_resource::<BrushElementDrag>()
|
||||
.init_resource::<BrushElementGizmoState>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
brush_edit_hotkeys,
|
||||
brush_element_pick,
|
||||
brush_element_drag,
|
||||
sync_brush_element_gizmo,
|
||||
brush_clip_commit,
|
||||
draw_brush_edit_overlays,
|
||||
)
|
||||
.chain()
|
||||
.run_if(scene_tools_active),
|
||||
);
|
||||
)
|
||||
.add_systems(Last, apply_brush_element_gizmo.run_if(scene_tools_active));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug, Clone, Copy)]
|
||||
pub struct BrushElementGizmo;
|
||||
|
||||
#[derive(Resource, Default, Debug, Clone)]
|
||||
struct BrushElementDrag {
|
||||
struct BrushElementGizmoState {
|
||||
entity: Option<Entity>,
|
||||
brush: Option<Entity>,
|
||||
old: Option<BrushDesc>,
|
||||
last_floor: Option<Vec3>,
|
||||
old_brush: Option<BrushDesc>,
|
||||
old_gizmo: Option<Transform>,
|
||||
last_gizmo: Option<Transform>,
|
||||
changed: bool,
|
||||
}
|
||||
|
||||
@@ -139,7 +147,9 @@ fn brush_edit_hotkeys(
|
||||
return Ok(());
|
||||
}
|
||||
let ctx = contexts.ctx_mut()?;
|
||||
if !viewport_keyboard_shortcuts_active(&ui_state, ctx, &buttons) || ctx.wants_keyboard_input() {
|
||||
if !viewport_keyboard_shortcuts_active(&ui_state, ctx, &buttons)
|
||||
|| ctx.egui_wants_keyboard_input()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
if keys.just_pressed(KeyCode::Escape) && mode.is_element_mode() {
|
||||
@@ -233,121 +243,272 @@ fn brush_element_pick(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn brush_element_drag(
|
||||
fn sync_brush_element_gizmo(
|
||||
mut commands: Commands,
|
||||
mode: Res<BrushEditMode>,
|
||||
selection: Res<BrushElementSelection>,
|
||||
mut drag: ResMut<BrushElementDrag>,
|
||||
mut active_operator: ResMut<ActiveOperator>,
|
||||
buttons: Res<ButtonInput<MouseButton>>,
|
||||
ui_state: Res<UiState>,
|
||||
cameras: Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
|
||||
mut brushes: Query<(&mut BrushDesc, &GlobalTransform)>,
|
||||
mut state: ResMut<BrushElementGizmoState>,
|
||||
brushes: Query<(&BrushDesc, &GlobalTransform)>,
|
||||
mut gizmos: Query<&mut Transform, With<BrushElementGizmo>>,
|
||||
) {
|
||||
if !mode.is_element_mode() || matches!(*mode, BrushEditMode::Clip) {
|
||||
clear_drag(&mut drag);
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
}
|
||||
let Some(brush_entity) = selection.brush else {
|
||||
clear_drag(&mut drag);
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
if selection.elements.is_empty() {
|
||||
clear_drag(&mut drag);
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
}
|
||||
let Some(pointer_pos) = ui_state.viewport_pointer_pos else {
|
||||
let Ok((brush, brush_transform)) = brushes.get(brush_entity) else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
let Some(current_floor) = pointer_floor_position(&cameras, pointer_pos, ui_state.viewport_rect)
|
||||
let Some(pivot) = selected_element_world_pivot(brush, brush_transform, &selection.elements)
|
||||
else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
|
||||
if buttons.just_pressed(MouseButton::Left) && drag.brush.is_none() {
|
||||
if let Ok((brush, _)) = brushes.get(brush_entity) {
|
||||
drag.brush = Some(brush_entity);
|
||||
drag.old = Some(brush.clone());
|
||||
drag.last_floor = Some(current_floor);
|
||||
drag.changed = false;
|
||||
}
|
||||
let rotation = brush_transform.to_scale_rotation_translation().1;
|
||||
let desired = Transform::from_translation(pivot).with_rotation(rotation);
|
||||
let needs_new_entity = state.brush != Some(brush_entity)
|
||||
|| state
|
||||
.entity
|
||||
.is_none_or(|entity| gizmos.get(entity).is_err());
|
||||
if needs_new_entity {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
let entity = commands
|
||||
.spawn((
|
||||
BrushElementGizmo,
|
||||
EditorOnly,
|
||||
GizmoTarget::default(),
|
||||
desired,
|
||||
GlobalTransform::default(),
|
||||
Visibility::Hidden,
|
||||
InheritedVisibility::default(),
|
||||
))
|
||||
.id();
|
||||
state.entity = Some(entity);
|
||||
state.brush = Some(brush_entity);
|
||||
state.old_brush = None;
|
||||
state.old_gizmo = Some(desired);
|
||||
state.last_gizmo = Some(desired);
|
||||
state.changed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if buttons.pressed(MouseButton::Left) && drag.brush == Some(brush_entity) {
|
||||
let Some(last_floor) = drag.last_floor else {
|
||||
drag.last_floor = Some(current_floor);
|
||||
let Some(entity) = state.entity else {
|
||||
return;
|
||||
};
|
||||
let Ok(mut transform) = gizmos.get_mut(entity) else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
if state.old_brush.is_none() {
|
||||
let current = *transform;
|
||||
if !gizmo_transform_is_active(&state, current) {
|
||||
*transform = desired;
|
||||
state.old_gizmo = Some(desired);
|
||||
state.last_gizmo = Some(desired);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn apply_brush_element_gizmo(
|
||||
mut commands: Commands,
|
||||
mode: Res<BrushEditMode>,
|
||||
selection: Res<BrushElementSelection>,
|
||||
mut state: ResMut<BrushElementGizmoState>,
|
||||
mut active_operator: ResMut<ActiveOperator>,
|
||||
mut brushes: Query<(&mut BrushDesc, &GlobalTransform)>,
|
||||
gizmos: Query<(&Transform, &GizmoTarget), With<BrushElementGizmo>>,
|
||||
) {
|
||||
if !mode.is_element_mode() || matches!(*mode, BrushEditMode::Clip) {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
}
|
||||
let (Some(gizmo_entity), Some(brush_entity)) = (state.entity, selection.brush) else {
|
||||
return;
|
||||
};
|
||||
if selection.elements.is_empty() || state.brush != Some(brush_entity) {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
}
|
||||
let Ok((gizmo_transform, target)) = gizmos.get(gizmo_entity) else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
|
||||
if target.is_active() {
|
||||
let Ok((mut brush, brush_transform)) = brushes.get_mut(brush_entity) else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
let world_delta = current_floor - last_floor;
|
||||
if world_delta.length_squared() <= 0.000001 {
|
||||
if state.old_brush.is_none() {
|
||||
state.old_brush = Some(brush.clone());
|
||||
state.old_gizmo = Some(*gizmo_transform);
|
||||
state.last_gizmo = Some(*gizmo_transform);
|
||||
state.changed = false;
|
||||
return;
|
||||
}
|
||||
if let Ok((mut brush, transform)) = brushes.get_mut(brush_entity) {
|
||||
let local_delta = transform.affine().inverse().transform_vector3(world_delta);
|
||||
if move_selected_elements(&mut brush, &selection.elements, local_delta) {
|
||||
drag.changed = true;
|
||||
drag.last_floor = Some(current_floor);
|
||||
let Some(last_gizmo) = state.last_gizmo else {
|
||||
state.last_gizmo = Some(*gizmo_transform);
|
||||
return;
|
||||
};
|
||||
if !transforms_nearly_equal(last_gizmo, *gizmo_transform)
|
||||
&& transform_selected_elements_by_gizmo(
|
||||
&mut brush,
|
||||
&selection.elements,
|
||||
brush_transform,
|
||||
last_gizmo,
|
||||
*gizmo_transform,
|
||||
)
|
||||
{
|
||||
state.changed = true;
|
||||
state.last_gizmo = Some(*gizmo_transform);
|
||||
set_brush_edit_status(
|
||||
&mut active_operator,
|
||||
OperatorPhase::Preview,
|
||||
format!(
|
||||
"Gizmo editing {} brush element(s)",
|
||||
selection.elements.len()
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if let (Some(old), Some(_)) = (state.old_brush.take(), state.old_gizmo.take()) {
|
||||
if state.changed {
|
||||
let Ok((mut brush, _)) = brushes.get_mut(brush_entity) else {
|
||||
clear_brush_element_gizmo(&mut commands, &mut state);
|
||||
return;
|
||||
};
|
||||
let new = brush.clone();
|
||||
let validation = validate_brush(&new);
|
||||
if validation.is_valid() {
|
||||
commands.queue(move |world: &mut World| {
|
||||
push_command(
|
||||
world,
|
||||
EditorCommand::SetBrush {
|
||||
entity: brush_entity,
|
||||
old: Some(old),
|
||||
new,
|
||||
},
|
||||
);
|
||||
});
|
||||
set_brush_edit_status(
|
||||
&mut active_operator,
|
||||
OperatorPhase::Preview,
|
||||
format!("Dragging {} element(s)", selection.elements.len()),
|
||||
OperatorPhase::Committed,
|
||||
"Committed brush element gizmo edit",
|
||||
);
|
||||
} else {
|
||||
*brush = old;
|
||||
let message = validation
|
||||
.diagnostics
|
||||
.iter()
|
||||
.find(|diagnostic| diagnostic.severity == BrushDiagnosticSeverity::Error)
|
||||
.map(|diagnostic| diagnostic.message.as_str())
|
||||
.unwrap_or("Brush edit produced invalid geometry");
|
||||
set_brush_edit_status(
|
||||
&mut active_operator,
|
||||
OperatorPhase::Blocked,
|
||||
format!("Rejected brush edit: {message}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
state.last_gizmo = Some(*gizmo_transform);
|
||||
state.changed = false;
|
||||
}
|
||||
|
||||
if buttons.just_released(MouseButton::Left) {
|
||||
if let (Some(brush), Some(old)) = (drag.brush, drag.old.take()) {
|
||||
if drag.changed {
|
||||
if let Ok((mut brush_desc, _)) = brushes.get_mut(brush) {
|
||||
let new = brush_desc.clone();
|
||||
let validation = validate_brush(&new);
|
||||
if validation.is_valid() {
|
||||
commands.queue(move |world: &mut World| {
|
||||
push_command(
|
||||
world,
|
||||
EditorCommand::SetBrush {
|
||||
entity: brush,
|
||||
old: Some(old),
|
||||
new,
|
||||
},
|
||||
);
|
||||
});
|
||||
set_brush_edit_status(
|
||||
&mut active_operator,
|
||||
OperatorPhase::Committed,
|
||||
"Committed brush element edit",
|
||||
);
|
||||
} else {
|
||||
*brush_desc = old;
|
||||
let message = validation
|
||||
.diagnostics
|
||||
.iter()
|
||||
.find(|diagnostic| {
|
||||
diagnostic.severity == BrushDiagnosticSeverity::Error
|
||||
})
|
||||
.map(|diagnostic| diagnostic.message.as_str())
|
||||
.unwrap_or("Brush edit produced invalid geometry");
|
||||
set_brush_edit_status(
|
||||
&mut active_operator,
|
||||
OperatorPhase::Blocked,
|
||||
format!("Rejected brush edit: {message}"),
|
||||
);
|
||||
}
|
||||
fn clear_brush_element_gizmo(commands: &mut Commands, state: &mut BrushElementGizmoState) {
|
||||
if let Some(entity) = state.entity.take() {
|
||||
if let Ok(mut entity_mut) = commands.get_entity(entity) {
|
||||
entity_mut.despawn();
|
||||
}
|
||||
}
|
||||
state.brush = None;
|
||||
state.old_brush = None;
|
||||
state.old_gizmo = None;
|
||||
state.last_gizmo = None;
|
||||
state.changed = false;
|
||||
}
|
||||
|
||||
fn selected_element_world_pivot(
|
||||
brush: &BrushDesc,
|
||||
transform: &GlobalTransform,
|
||||
selected: &[BrushElementKey],
|
||||
) -> Option<Vec3> {
|
||||
let anchors = selected_anchor_positions(brush, selected);
|
||||
if anchors.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let affine = transform.affine();
|
||||
Some(
|
||||
anchors
|
||||
.iter()
|
||||
.map(|anchor| affine.transform_point3(*anchor))
|
||||
.sum::<Vec3>()
|
||||
/ anchors.len() as f32,
|
||||
)
|
||||
}
|
||||
|
||||
fn gizmo_transform_is_active(state: &BrushElementGizmoState, transform: Transform) -> bool {
|
||||
state
|
||||
.last_gizmo
|
||||
.is_some_and(|last| !transforms_nearly_equal(last, transform))
|
||||
|| state.old_brush.is_some()
|
||||
}
|
||||
|
||||
fn transform_selected_elements_by_gizmo(
|
||||
brush: &mut BrushDesc,
|
||||
selected: &[BrushElementKey],
|
||||
brush_transform: &GlobalTransform,
|
||||
old_gizmo: Transform,
|
||||
new_gizmo: Transform,
|
||||
) -> bool {
|
||||
let anchors = selected_anchor_positions(brush, selected);
|
||||
if anchors.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let old_world_from_gizmo = old_gizmo.compute_affine();
|
||||
let new_world_from_gizmo = new_gizmo.compute_affine();
|
||||
let world_delta = new_world_from_gizmo * old_world_from_gizmo.inverse();
|
||||
let brush_from_world = brush_transform.affine().inverse();
|
||||
let world_from_brush = brush_transform.affine();
|
||||
let mut changed = false;
|
||||
for face in &mut brush.faces {
|
||||
for vertex in &mut face.vertices {
|
||||
if anchors
|
||||
.iter()
|
||||
.any(|anchor| vertex.distance_squared(*anchor) <= 0.0001)
|
||||
{
|
||||
let world = world_from_brush.transform_point3(*vertex);
|
||||
let transformed = world_delta.transform_point3(world);
|
||||
let local = brush_from_world.transform_point3(transformed);
|
||||
if vertex.distance_squared(local) > 0.000001 {
|
||||
*vertex = local;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
clear_drag(&mut drag);
|
||||
}
|
||||
if changed {
|
||||
recompute_face_planes(brush);
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
fn clear_drag(drag: &mut BrushElementDrag) {
|
||||
drag.brush = None;
|
||||
drag.old = None;
|
||||
drag.last_floor = None;
|
||||
drag.changed = false;
|
||||
fn transforms_nearly_equal(a: Transform, b: Transform) -> bool {
|
||||
a.translation.distance_squared(b.translation) <= 0.000001
|
||||
&& a.rotation.dot(b.rotation).abs() >= 0.99999
|
||||
&& a.scale.distance_squared(b.scale) <= 0.000001
|
||||
}
|
||||
|
||||
fn brush_clip_commit(
|
||||
@@ -677,50 +838,6 @@ fn pick_element(
|
||||
}
|
||||
}
|
||||
|
||||
fn pointer_floor_position(
|
||||
cameras: &Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
|
||||
pointer_pos: egui::Pos2,
|
||||
scene_rect: egui::Rect,
|
||||
) -> Option<Vec3> {
|
||||
let ray = viewport_ray(cameras, pointer_pos, scene_rect)?;
|
||||
let direction = ray.direction.as_vec3();
|
||||
if direction.y.abs() < 0.0001 {
|
||||
return Some(ray.origin);
|
||||
}
|
||||
let t = -ray.origin.y / direction.y;
|
||||
Some(ray.origin + direction * t.max(0.0))
|
||||
}
|
||||
|
||||
fn move_selected_elements(
|
||||
brush: &mut BrushDesc,
|
||||
selected: &[BrushElementKey],
|
||||
delta: Vec3,
|
||||
) -> bool {
|
||||
if delta.length_squared() <= 0.000001 {
|
||||
return false;
|
||||
}
|
||||
let anchors = selected_anchor_positions(brush, selected);
|
||||
if anchors.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let mut changed = false;
|
||||
for face in &mut brush.faces {
|
||||
for vertex in &mut face.vertices {
|
||||
if anchors
|
||||
.iter()
|
||||
.any(|anchor| vertex.distance_squared(*anchor) <= 0.0001)
|
||||
{
|
||||
*vertex += delta;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
recompute_face_planes(brush);
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
fn selected_anchor_positions(brush: &BrushDesc, selected: &[BrushElementKey]) -> Vec<Vec3> {
|
||||
let mut anchors = Vec::new();
|
||||
for element in selected {
|
||||
@@ -986,10 +1103,12 @@ mod tests {
|
||||
.count();
|
||||
let face = brush.faces[0].id.clone();
|
||||
|
||||
let changed = move_selected_elements(
|
||||
let changed = transform_selected_elements_by_gizmo(
|
||||
&mut brush,
|
||||
&[BrushElementKey::Vertex { face, index: 0 }],
|
||||
Vec3::new(0.5, 0.0, 0.0),
|
||||
&GlobalTransform::default(),
|
||||
Transform::default(),
|
||||
Transform::from_translation(Vec3::new(0.5, 0.0, 0.0)),
|
||||
);
|
||||
|
||||
let after = brush
|
||||
@@ -1006,10 +1125,12 @@ mod tests {
|
||||
fn collapsed_face_move_produces_invalid_brush() {
|
||||
let mut brush = BrushDesc::default();
|
||||
let face = brush.faces[0].id.clone();
|
||||
assert!(move_selected_elements(
|
||||
assert!(transform_selected_elements_by_gizmo(
|
||||
&mut brush,
|
||||
&[BrushElementKey::Face { face }],
|
||||
Vec3::new(-1.0, 0.0, 0.0),
|
||||
&GlobalTransform::default(),
|
||||
Transform::default(),
|
||||
Transform::from_translation(Vec3::new(-1.0, 0.0, 0.0)),
|
||||
));
|
||||
assert!(!validate_brush(&brush).is_valid());
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ fn brush_tool_input(
|
||||
}
|
||||
|
||||
let ctx = contexts.ctx_mut()?;
|
||||
let egui_keyboard_busy = ctx.wants_keyboard_input();
|
||||
let egui_keyboard_busy = ctx.egui_wants_keyboard_input();
|
||||
let keyboard_available =
|
||||
viewport_keyboard_shortcuts_active(&ui_state, ctx, &buttons) && !egui_keyboard_busy;
|
||||
|
||||
@@ -591,13 +591,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn draw_brush_status_explains_invalid_shape() {
|
||||
let mut tool = BrushToolState::default();
|
||||
tool.vertices = vec![
|
||||
Vec3::new(-1.0, 0.0, -1.0),
|
||||
Vec3::new(1.0, 0.0, -1.0),
|
||||
Vec3::new(-1.0, 0.0, 1.0),
|
||||
Vec3::new(1.0, 0.0, 1.0),
|
||||
];
|
||||
let tool = BrushToolState {
|
||||
vertices: vec![
|
||||
Vec3::new(-1.0, 0.0, -1.0),
|
||||
Vec3::new(1.0, 0.0, -1.0),
|
||||
Vec3::new(-1.0, 0.0, 1.0),
|
||||
Vec3::new(1.0, 0.0, 1.0),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
let status = draw_brush_status(&tool);
|
||||
|
||||
assert!(status.contains("polygon edges cross"));
|
||||
|
||||
@@ -87,6 +87,7 @@ fn spawn_editor_camera(
|
||||
RenderLayers::default(),
|
||||
GizmoCamera,
|
||||
Camera3d::default(),
|
||||
Msaa::Off,
|
||||
Camera {
|
||||
clear_color: ClearColorConfig::Custom(Color::srgba(0.0, 0.0, 0.0, 1.0)),
|
||||
..default()
|
||||
@@ -149,12 +150,12 @@ fn update_editor_camera(
|
||||
if input_state.mode.is_none() && navigation_pressed {
|
||||
return Ok(());
|
||||
}
|
||||
if !in_scene && input_state.mode.is_none() && ctx.wants_pointer_input() {
|
||||
if !in_scene && input_state.mode.is_none() && ctx.egui_wants_pointer_input() {
|
||||
return Ok(());
|
||||
}
|
||||
if in_scene
|
||||
&& input_state.mode.is_none()
|
||||
&& ctx.wants_pointer_input()
|
||||
&& ctx.egui_wants_pointer_input()
|
||||
&& !buttons.pressed(MouseButton::Right)
|
||||
{
|
||||
return Ok(());
|
||||
@@ -162,7 +163,7 @@ fn update_editor_camera(
|
||||
|
||||
let dt = time.delta_secs();
|
||||
let raw_scroll_delta: f32 = scroll.read().map(|event| event.y).sum();
|
||||
let scroll_delta = if in_scene && !ctx.wants_pointer_input() {
|
||||
let scroll_delta = if in_scene && !ctx.egui_wants_pointer_input() {
|
||||
raw_scroll_delta
|
||||
} else {
|
||||
0.0
|
||||
|
||||
@@ -154,6 +154,10 @@ pub fn snap_translation(position: Vec3, settings: &ViewportSettings) -> Vec3 {
|
||||
)
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy system parameters represent independent editor input and scene state"
|
||||
)]
|
||||
fn focus_selection_hotkey(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
buttons: Res<ButtonInput<MouseButton>>,
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use bevy::anti_alias::taa::TemporalAntiAliasing;
|
||||
use bevy::camera::Hdr;
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::pbr::{Atmosphere, ScatteringMedium, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::light::atmosphere::ScatteringMedium;
|
||||
use bevy::pbr::{AtmosphereSettings, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::post_process::auto_exposure::AutoExposure;
|
||||
use bevy::post_process::bloom::Bloom;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::view::Hdr;
|
||||
use game::rendering::{
|
||||
clear_viewport_camera_stack, has_local_shadow_lights, resolve_viewport_camera_owner,
|
||||
sync_viewport_camera_stack, SolariRaytracingSceneStats, ViewportCameraOwner,
|
||||
ViewportFxSnapshot, ViewportStackApply,
|
||||
sync_project_atmosphere, sync_viewport_camera_stack, ProjectAtmosphere,
|
||||
SolariRaytracingSceneStats, ViewportCameraOwner, ViewportFxSnapshot, ViewportStackApply,
|
||||
};
|
||||
use settings::{
|
||||
ActiveCameraRenderProfile, EffectiveRenderStack, GiPath, ProjectRenderCamera, ProjectSettings,
|
||||
@@ -65,7 +66,7 @@ type CameraFxState = (bool, bool, bool, bool, bool, bool, bool, bool);
|
||||
fn fx_snapshot(state: CameraFxState) -> ViewportFxSnapshot {
|
||||
ViewportFxSnapshot {
|
||||
has_stack: state.0,
|
||||
has_atmosphere: state.1,
|
||||
has_atmosphere_settings: state.1,
|
||||
has_tonemapping: state.2,
|
||||
has_bloom: state.3,
|
||||
has_ssao: state.4,
|
||||
@@ -101,9 +102,10 @@ fn sync_project_render_view(
|
||||
editor_cameras: Query<Entity, With<EditorCamera>>,
|
||||
player_cameras: Query<Entity, With<PlayerCamera>>,
|
||||
stacked: Query<Entity, With<ProjectRenderCamera>>,
|
||||
atmospheres: Query<Entity, With<ProjectAtmosphere>>,
|
||||
camera_fx: Query<(
|
||||
Has<ProjectRenderCamera>,
|
||||
Has<Atmosphere>,
|
||||
Has<AtmosphereSettings>,
|
||||
Has<Tonemapping>,
|
||||
Has<Bloom>,
|
||||
Has<ScreenSpaceAmbientOcclusion>,
|
||||
@@ -189,6 +191,12 @@ fn sync_project_render_view(
|
||||
|| solari_readiness_changed
|
||||
|| local_shadow_lights_changed
|
||||
{
|
||||
sync_project_atmosphere(
|
||||
&mut commands,
|
||||
&mut mediums,
|
||||
profile.atmosphere,
|
||||
atmospheres.iter(),
|
||||
);
|
||||
let force_full_apply = owner_changed || target_changed || solari_readiness_changed;
|
||||
for entity in &active {
|
||||
let apply = if force_full_apply {
|
||||
|
||||
@@ -99,7 +99,7 @@ fn active_camera_tab(world: &mut World, ui: &mut egui::Ui) {
|
||||
{
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(255, 180, 100),
|
||||
"Solari deferred: directional lights and emissive meshes affect lighting; point/spot LightDesc components are disabled in Bevy 0.18.",
|
||||
"Solari deferred: directional lights and emissive meshes affect lighting; point/spot LightDesc components are disabled in Bevy 0.19.",
|
||||
);
|
||||
} else if stack.fallback_reason == Some(RenderFallbackReason::RtUnsupported)
|
||||
|| (!caps.rt_supported && profile.gi_path == GiPath::Forward)
|
||||
@@ -221,17 +221,17 @@ fn runtime_lighting_summary(world: &mut World, ui: &mut egui::Ui) {
|
||||
let shadowed_directional = world
|
||||
.query::<&DirectionalLight>()
|
||||
.iter(world)
|
||||
.filter(|light| light.shadows_enabled)
|
||||
.filter(|light| light.shadow_maps_enabled)
|
||||
.count();
|
||||
let shadowed_point = world
|
||||
.query::<&PointLight>()
|
||||
.iter(world)
|
||||
.filter(|light| light.shadows_enabled)
|
||||
.filter(|light| light.shadow_maps_enabled)
|
||||
.count();
|
||||
let shadowed_spot = world
|
||||
.query::<&SpotLight>()
|
||||
.iter(world)
|
||||
.filter(|light| light.shadows_enabled)
|
||||
.filter(|light| light.shadow_maps_enabled)
|
||||
.count();
|
||||
ui.label(format!(
|
||||
"Counts: {directional} directional, {point} point, {spot} spot"
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::ui::hierarchy_ops::is_entity_locked;
|
||||
use crate::ui::hierarchy_state::HierarchyPanelState;
|
||||
use crate::ui::UiState;
|
||||
use crate::viewport::actor_icons::ActorIconProxy;
|
||||
use crate::viewport::brush_edit::BrushEditMode;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementGizmo};
|
||||
use crate::viewport::brush_tool::BrushToolState;
|
||||
use crate::viewport::ViewportDisplayMode;
|
||||
use crate::visualizers::EditorVisualizerProxy;
|
||||
@@ -238,6 +238,10 @@ fn cycle_overlapping_viewport_pick(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "viewport picking combines explicit camera, ray-cast, selection, and input state"
|
||||
)]
|
||||
fn apply_viewport_pick(
|
||||
hierarchy: Option<&HierarchyPanelState>,
|
||||
ui_state: &mut UiState,
|
||||
@@ -369,30 +373,40 @@ fn pick_target_for_entity(entity: Entity, pick_targets: &PickTargetQueries) -> O
|
||||
None
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy system parameters represent independent selection and gizmo state"
|
||||
)]
|
||||
fn sync_gizmo_targets(
|
||||
mut ui_state: ResMut<UiState>,
|
||||
mut selected: ResMut<SelectedEntity>,
|
||||
mut commands: Commands,
|
||||
targets: Query<Entity, With<GizmoTarget>>,
|
||||
targets: Query<(Entity, Option<&BrushElementGizmo>), With<GizmoTarget>>,
|
||||
level_objects: Query<(), (With<LevelObject>, Without<EditorOnly>)>,
|
||||
editor_only: Query<(), With<EditorOnly>>,
|
||||
transforms: Query<(), With<Transform>>,
|
||||
hierarchy: Option<Res<HierarchyPanelState>>,
|
||||
display: Res<ViewportDisplayMode>,
|
||||
brush_mode: Res<BrushEditMode>,
|
||||
) {
|
||||
ui_state
|
||||
.selected_entities
|
||||
.retain(|entity| transforms.contains(entity) && !editor_only.contains(entity));
|
||||
selected.0 = ui_state.selected_entities.as_slice().first().copied();
|
||||
|
||||
if display.clean_game_view {
|
||||
for entity in &targets {
|
||||
commands.entity(entity).remove::<GizmoTarget>();
|
||||
if display.clean_game_view || brush_mode.is_element_mode() {
|
||||
for (entity, brush_element_gizmo) in &targets {
|
||||
if brush_element_gizmo.is_none() {
|
||||
commands.entity(entity).remove::<GizmoTarget>();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for entity in &targets {
|
||||
for (entity, brush_element_gizmo) in &targets {
|
||||
if brush_element_gizmo.is_some() {
|
||||
continue;
|
||||
}
|
||||
if !ui_state.selected_entities.contains(entity) {
|
||||
commands.entity(entity).remove::<GizmoTarget>();
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ macro_rules! impl_outline_material {
|
||||
) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
|
||||
descriptor.primitive.cull_mode = Some(Face::Front);
|
||||
if let Some(depth) = &mut descriptor.depth_stencil {
|
||||
depth.depth_write_enabled = false;
|
||||
depth.depth_compare = $depth;
|
||||
depth.depth_write_enabled = Some(false);
|
||||
depth.depth_compare = Some($depth);
|
||||
}
|
||||
if let Some(fragment) = &mut descriptor.fragment {
|
||||
if let Some(target) = fragment.targets.first_mut().and_then(|t| t.as_mut()) {
|
||||
@@ -270,6 +270,10 @@ fn sync_selection_outline_meshes(
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "selection bounds combine distinct authored geometry and physics sources"
|
||||
)]
|
||||
fn selection_bounds(
|
||||
root: Entity,
|
||||
children: &Query<&Children>,
|
||||
|
||||
@@ -44,6 +44,10 @@ impl Plugin for EditorViewportModePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy system parameters represent independent viewport render state"
|
||||
)]
|
||||
fn apply_viewport_mode_on_change(
|
||||
mode: Res<EditorViewportMode>,
|
||||
mut last: Local<Option<EditorViewportMode>>,
|
||||
|
||||
@@ -16,9 +16,10 @@ pub mod rendering {
|
||||
clear_viewport_camera_stack, effective_gi_path_for_camera, effective_viewport_gi_path,
|
||||
effective_viewport_render_stack, has_local_shadow_lights, hdr_enabled_profile,
|
||||
patch_camera_effects, resolve_viewport_camera_owner, strip_project_camera_fx,
|
||||
sync_optional_rendering_fx, sync_viewport_camera_stack, world_has_local_shadow_lights,
|
||||
FullscreenEffectsPlugin, SolariRaytracingSceneStats, SolariRenderingPlugin,
|
||||
ViewportCameraOwner, ViewportFxSnapshot, ViewportStackApply, HDR_ENV_VAR,
|
||||
sync_optional_rendering_fx, sync_project_atmosphere, sync_viewport_camera_stack,
|
||||
world_has_local_shadow_lights, FullscreenEffectsPlugin, ProjectAtmosphere,
|
||||
SolariRaytracingSceneStats, SolariRenderingPlugin, ViewportCameraOwner, ViewportFxSnapshot,
|
||||
ViewportStackApply, HDR_ENV_VAR,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ mod hot {
|
||||
use bevy::prelude::*;
|
||||
use bevy::time::Fixed;
|
||||
use bevy::window::{CursorOptions, PrimaryWindow};
|
||||
use game_hot::SolariRaytracingSceneStats;
|
||||
use game_hot::{ProjectAtmosphere, SolariRaytracingSceneStats};
|
||||
use protocol::PlayerInputIntent;
|
||||
use settings::{
|
||||
ActiveCameraRenderProfile, ProjectRenderCamera, ProjectSettings, RenderingCapabilities,
|
||||
|
||||
@@ -17,10 +17,10 @@ pub use rendering::{
|
||||
patch_camera_effects, refresh_player_camera_fx, resolve_active_camera_render_profile_system,
|
||||
resolve_viewport_camera_owner, sample_volumes_at, setup_project_camera_effects,
|
||||
snapshot_viewport_fx, strip_project_camera_fx, sync_optional_rendering_fx,
|
||||
sync_viewport_camera_stack, tag_player_camera, world_has_local_shadow_lights,
|
||||
AutoExposureRenderingPlugin, FullscreenEffectsPlugin, SolariRaytracingSceneStats,
|
||||
SolariRenderingPlugin, ViewportCameraOwner, ViewportFxSnapshot, ViewportStackApply,
|
||||
HDR_ENV_VAR,
|
||||
sync_project_atmosphere, sync_viewport_camera_stack, tag_player_camera,
|
||||
world_has_local_shadow_lights, AutoExposureRenderingPlugin, FullscreenEffectsPlugin,
|
||||
ProjectAtmosphere, SolariRaytracingSceneStats, SolariRenderingPlugin, ViewportCameraOwner,
|
||||
ViewportFxSnapshot, ViewportStackApply, HDR_ENV_VAR,
|
||||
};
|
||||
pub use sim_systems::{apply_player_intent, move_and_slide, sync_player_physics_position};
|
||||
pub use world::{
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn spawn_player(mut commands: Commands, existing: Query<(), With<Player>>) {
|
||||
parent.spawn((
|
||||
PlayerCamera,
|
||||
Camera3d::default(),
|
||||
Msaa::Off,
|
||||
Camera {
|
||||
clear_color: ClearColorConfig::Custom(Color::srgba(0.0, 0.0, 0.0, 1.0)),
|
||||
..default()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//! Assembles the high-fidelity rendering stack on project cameras.
|
||||
|
||||
use bevy::anti_alias::taa::TemporalAntiAliasing;
|
||||
use bevy::camera::Exposure;
|
||||
use bevy::camera::{Exposure, Hdr};
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::pbr::{Atmosphere, AtmosphereSettings, ScatteringMedium, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::light::{atmosphere::ScatteringMedium, Atmosphere};
|
||||
use bevy::pbr::{AtmosphereSettings, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::post_process::auto_exposure::AutoExposure;
|
||||
use bevy::post_process::bloom::Bloom;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::view::Hdr;
|
||||
use settings::{
|
||||
effective_auto_exposure, ActiveCameraRenderProfile, GiPath, ProjectRenderCamera,
|
||||
ProjectSettings, RenderingCapabilities, RenderingSettings,
|
||||
@@ -20,6 +20,10 @@ use super::fullscreen_effects::{strip_fullscreen_effects, sync_fullscreen_effect
|
||||
use super::solari::{strip_gi_path, sync_gi_path, SolariRaytracingSceneStats};
|
||||
use super::viewport_camera::effective_viewport_gi_path;
|
||||
|
||||
/// Marker for the single project-owned atmosphere entity used by Bevy 0.19 cameras.
|
||||
#[derive(Component, Debug, Clone, Copy)]
|
||||
pub struct ProjectAtmosphere;
|
||||
|
||||
/// Environment variable name for HDR override (matches game launch).
|
||||
pub const HDR_ENV_VAR: &str = "BEVY_FPS_HDR";
|
||||
|
||||
@@ -73,6 +77,10 @@ pub fn hdr_required_for_render_stack(
|
||||
|
||||
/// Applies the shared project rendering profile to all [`ProjectRenderCamera`] entities.
|
||||
#[unsafe(no_mangle)]
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy systems expose independent render resources and light queries"
|
||||
)]
|
||||
pub fn setup_project_camera_effects(
|
||||
mut commands: Commands,
|
||||
mut mediums: ResMut<Assets<ScatteringMedium>>,
|
||||
@@ -81,6 +89,7 @@ pub fn setup_project_camera_effects(
|
||||
caps: Option<Res<RenderingCapabilities>>,
|
||||
solari_stats: Option<Res<SolariRaytracingSceneStats>>,
|
||||
cameras: Query<Entity, With<ProjectRenderCamera>>,
|
||||
atmospheres: Query<Entity, With<ProjectAtmosphere>>,
|
||||
points: Query<&PointLight>,
|
||||
spots: Query<&SpotLight>,
|
||||
) {
|
||||
@@ -93,6 +102,12 @@ pub fn setup_project_camera_effects(
|
||||
)
|
||||
});
|
||||
let has_local_shadow_lights = super::viewport_camera::has_local_shadow_lights(&points, &spots);
|
||||
sync_project_atmosphere(
|
||||
&mut commands,
|
||||
&mut mediums,
|
||||
active.atmosphere,
|
||||
atmospheres.iter(),
|
||||
);
|
||||
for entity in &cameras {
|
||||
apply_camera_render_profile(
|
||||
&mut commands,
|
||||
@@ -106,6 +121,29 @@ pub fn setup_project_camera_effects(
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the Bevy 0.19 atmosphere model stable: one world entity, camera settings per view.
|
||||
pub fn sync_project_atmosphere(
|
||||
commands: &mut Commands,
|
||||
mediums: &mut Assets<ScatteringMedium>,
|
||||
enabled: bool,
|
||||
atmospheres: impl IntoIterator<Item = Entity>,
|
||||
) {
|
||||
let existing: Vec<Entity> = atmospheres.into_iter().collect();
|
||||
if enabled {
|
||||
if existing.is_empty() {
|
||||
let medium = mediums.add(ScatteringMedium::default());
|
||||
commands.spawn((ProjectAtmosphere, Atmosphere::earth(medium)));
|
||||
}
|
||||
for entity in existing.iter().skip(1) {
|
||||
commands.entity(*entity).despawn();
|
||||
}
|
||||
} else {
|
||||
for entity in existing {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts or removes manual [`Exposure`] vs [`AutoExposure`] for the active profile.
|
||||
pub fn sync_exposure(
|
||||
commands: &mut Commands,
|
||||
@@ -135,7 +173,7 @@ pub fn apply_camera_render_profile(
|
||||
profile: &ActiveCameraRenderProfile,
|
||||
caps: &RenderingCapabilities,
|
||||
solari_stats: Option<&SolariRaytracingSceneStats>,
|
||||
mediums: &mut Assets<ScatteringMedium>,
|
||||
_mediums: &mut Assets<ScatteringMedium>,
|
||||
has_local_shadow_lights: bool,
|
||||
) {
|
||||
commands.entity(entity).insert(Msaa::Off);
|
||||
@@ -155,13 +193,15 @@ pub fn apply_camera_render_profile(
|
||||
});
|
||||
|
||||
if profile.atmosphere {
|
||||
let medium = mediums.add(ScatteringMedium::default());
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(Atmosphere::earthlike(medium));
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<Atmosphere>()
|
||||
.insert(AtmosphereSettings::default());
|
||||
} else {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<Atmosphere>()
|
||||
.remove::<AtmosphereSettings>();
|
||||
}
|
||||
if profile.tonemapping_aces {
|
||||
commands.entity(entity).insert(Tonemapping::AcesFitted);
|
||||
@@ -245,8 +285,8 @@ pub fn sync_optional_rendering_fx(
|
||||
profile: &ActiveCameraRenderProfile,
|
||||
caps: &RenderingCapabilities,
|
||||
solari_stats: Option<&SolariRaytracingSceneStats>,
|
||||
mediums: &mut Assets<ScatteringMedium>,
|
||||
has_atmosphere: bool,
|
||||
_mediums: &mut Assets<ScatteringMedium>,
|
||||
has_atmosphere_settings: bool,
|
||||
has_tonemapping: bool,
|
||||
has_bloom: bool,
|
||||
has_ssao: bool,
|
||||
@@ -258,19 +298,18 @@ pub fn sync_optional_rendering_fx(
|
||||
let effective_gi =
|
||||
effective_viewport_gi_path(profile.gi_path, caps, solari_stats, has_local_shadow_lights);
|
||||
|
||||
if profile.atmosphere && !has_atmosphere {
|
||||
let medium = mediums.add(ScatteringMedium::default());
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(Atmosphere::earthlike(medium));
|
||||
if profile.atmosphere && !has_atmosphere_settings {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<Atmosphere>()
|
||||
.insert(AtmosphereSettings::default());
|
||||
} else if !profile.atmosphere && has_atmosphere {
|
||||
} else if !profile.atmosphere && has_atmosphere_settings {
|
||||
commands
|
||||
.entity(entity)
|
||||
.remove::<Atmosphere>()
|
||||
.remove::<AtmosphereSettings>();
|
||||
} else if profile.atmosphere {
|
||||
commands.entity(entity).remove::<Atmosphere>();
|
||||
}
|
||||
|
||||
if profile.tonemapping_aces && !has_tonemapping {
|
||||
@@ -365,31 +404,6 @@ pub fn patch_camera_effects(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn solari_forces_hdr_render_target() {
|
||||
assert!(hdr_required_for_render_stack(
|
||||
false,
|
||||
false,
|
||||
GiPath::SolariDeferred
|
||||
));
|
||||
assert!(hdr_required_for_render_stack(true, false, GiPath::Forward));
|
||||
assert!(!hdr_required_for_render_stack(
|
||||
false,
|
||||
false,
|
||||
GiPath::Forward
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn atmosphere_forces_hdr_render_target() {
|
||||
assert!(hdr_required_for_render_stack(false, true, GiPath::Forward));
|
||||
}
|
||||
}
|
||||
|
||||
/// Re-applies player camera FX tags after a hot reload.
|
||||
pub fn refresh_player_camera_fx(world: &mut World) {
|
||||
let Some(settings) = world.get_resource::<ProjectSettings>().cloned() else {
|
||||
@@ -419,6 +433,16 @@ pub fn refresh_player_camera_fx(world: &mut World) {
|
||||
}
|
||||
|
||||
world.resource_scope(|world, mut mediums: Mut<Assets<ScatteringMedium>>| {
|
||||
let atmospheres: Vec<Entity> = world
|
||||
.query_filtered::<Entity, With<ProjectAtmosphere>>()
|
||||
.iter(world)
|
||||
.collect();
|
||||
sync_project_atmosphere(
|
||||
&mut world.commands(),
|
||||
&mut mediums,
|
||||
profile.atmosphere,
|
||||
atmospheres,
|
||||
);
|
||||
for entity in cameras {
|
||||
apply_camera_render_profile(
|
||||
&mut world.commands(),
|
||||
@@ -432,3 +456,28 @@ pub fn refresh_player_camera_fx(world: &mut World) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn solari_forces_hdr_render_target() {
|
||||
assert!(hdr_required_for_render_stack(
|
||||
false,
|
||||
false,
|
||||
GiPath::SolariDeferred
|
||||
));
|
||||
assert!(hdr_required_for_render_stack(true, false, GiPath::Forward));
|
||||
assert!(!hdr_required_for_render_stack(
|
||||
false,
|
||||
false,
|
||||
GiPath::Forward
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn atmosphere_forces_hdr_render_target() {
|
||||
assert!(hdr_required_for_render_stack(false, true, GiPath::Forward));
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_component::ExtractComponent;
|
||||
use bevy::render::render_graph::{InternedRenderLabel, RenderLabel, RenderSubGraph};
|
||||
use bevy::render::render_resource::ShaderType;
|
||||
use bevy::shader::ShaderRef;
|
||||
use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d};
|
||||
use bevy_core_pipeline::fullscreen_material::{FullscreenMaterial, FullscreenMaterialPlugin};
|
||||
use bevy_core_pipeline::tonemapping::tonemapping;
|
||||
use bevy_core_pipeline::Core3dSystems;
|
||||
use shared::{PostProcessEffectAsset, PostProcessEffectKind};
|
||||
|
||||
/// Vignette fullscreen pass.
|
||||
@@ -21,16 +21,10 @@ impl FullscreenMaterial for VignetteFx {
|
||||
"post_fx/vignette.wgsl".into()
|
||||
}
|
||||
|
||||
fn node_edges() -> Vec<InternedRenderLabel> {
|
||||
vec![
|
||||
Node3d::Tonemapping.intern(),
|
||||
Self::node_label().intern(),
|
||||
Node3d::EndMainPassPostProcessing.intern(),
|
||||
]
|
||||
}
|
||||
|
||||
fn sub_graph() -> Option<bevy::render::render_graph::InternedRenderSubGraph> {
|
||||
Some(Core3d.intern())
|
||||
fn schedule_configs(
|
||||
system: bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem>,
|
||||
) -> bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem> {
|
||||
system.in_set(Core3dSystems::PostProcess).after(tonemapping)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,16 +40,10 @@ impl FullscreenMaterial for ChromaticAberrationFx {
|
||||
"post_fx/chromatic_aberration.wgsl".into()
|
||||
}
|
||||
|
||||
fn node_edges() -> Vec<InternedRenderLabel> {
|
||||
vec![
|
||||
Node3d::Tonemapping.intern(),
|
||||
Self::node_label().intern(),
|
||||
Node3d::EndMainPassPostProcessing.intern(),
|
||||
]
|
||||
}
|
||||
|
||||
fn sub_graph() -> Option<bevy::render::render_graph::InternedRenderSubGraph> {
|
||||
Some(Core3d.intern())
|
||||
fn schedule_configs(
|
||||
system: bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem>,
|
||||
) -> bevy::ecs::schedule::ScheduleConfigs<bevy::ecs::system::BoxedSystem> {
|
||||
system.in_set(Core3dSystems::PostProcess).after(tonemapping)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub use camera_fx::{
|
||||
apply_camera_render_profile, apply_project_camera_fx, camera_auto_exposure_active,
|
||||
hdr_enabled_profile, patch_camera_effects, refresh_player_camera_fx,
|
||||
setup_project_camera_effects, strip_project_camera_fx, sync_optional_rendering_fx,
|
||||
tag_player_camera, HDR_ENV_VAR,
|
||||
sync_project_atmosphere, tag_player_camera, ProjectAtmosphere, HDR_ENV_VAR,
|
||||
};
|
||||
pub use fullscreen_effects::FullscreenEffectsPlugin;
|
||||
pub use solari::{effective_gi_path_for_camera, SolariRaytracingSceneStats, SolariRenderingPlugin};
|
||||
|
||||
@@ -204,6 +204,10 @@ fn sync_auxiliary_camera_deferred_prepass(
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy systems expose independent render assets and scene queries"
|
||||
)]
|
||||
fn sync_hydrated_raytracing_meshes(
|
||||
caps: Res<RenderingCapabilities>,
|
||||
mut commands: Commands,
|
||||
@@ -510,7 +514,9 @@ mod tests {
|
||||
|
||||
let mut state: SystemState<(Query<&ChildOf>, Query<(), With<LevelObject>>)> =
|
||||
SystemState::new(&mut world);
|
||||
let (parents, level_roots) = state.get(&world);
|
||||
let (parents, level_roots) = state
|
||||
.get(&world)
|
||||
.expect("solari test system params should be valid");
|
||||
|
||||
assert!(has_level_object_ancestor(child, &parents, &level_roots));
|
||||
assert!(has_level_object_ancestor(root, &parents, &level_roots));
|
||||
@@ -523,7 +529,9 @@ mod tests {
|
||||
|
||||
let mut state: SystemState<(Query<&ChildOf>, Query<(), With<LevelObject>>)> =
|
||||
SystemState::new(&mut world);
|
||||
let (parents, level_roots) = state.get(&world);
|
||||
let (parents, level_roots) = state
|
||||
.get(&world)
|
||||
.expect("solari test system params should be valid");
|
||||
|
||||
assert!(!has_level_object_ancestor(orphan, &parents, &level_roots));
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ use super::camera_fx::{
|
||||
};
|
||||
use super::solari::SolariRaytracingSceneStats;
|
||||
use bevy::anti_alias::taa::TemporalAntiAliasing;
|
||||
use bevy::camera::Exposure;
|
||||
use bevy::camera::{Exposure, Hdr};
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::pbr::{Atmosphere, ScatteringMedium, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::light::atmosphere::ScatteringMedium;
|
||||
use bevy::pbr::{AtmosphereSettings, ScreenSpaceAmbientOcclusion};
|
||||
use bevy::post_process::auto_exposure::AutoExposure;
|
||||
use bevy::post_process::bloom::Bloom;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::view::Hdr;
|
||||
use settings::{
|
||||
resolve_effective_render_stack, write_effective_render_stack, ActiveCameraRenderProfile,
|
||||
EffectiveRenderStack, GiPath, ProjectRenderCamera, RenderingCapabilities,
|
||||
@@ -39,18 +39,18 @@ pub fn resolve_viewport_camera_owner(
|
||||
|
||||
/// True when any point or spot light in the world casts shadows.
|
||||
pub fn has_local_shadow_lights(points: &Query<&PointLight>, spots: &Query<&SpotLight>) -> bool {
|
||||
points.iter().any(|l| l.shadows_enabled) || spots.iter().any(|l| l.shadows_enabled)
|
||||
points.iter().any(|l| l.shadow_maps_enabled) || spots.iter().any(|l| l.shadow_maps_enabled)
|
||||
}
|
||||
|
||||
/// [`has_local_shadow_lights`] for exclusive [`World`] access (hot reload, diagnostics).
|
||||
pub fn world_has_local_shadow_lights(world: &mut World) -> bool {
|
||||
for pl in world.query::<&PointLight>().iter(world) {
|
||||
if pl.shadows_enabled {
|
||||
if pl.shadow_maps_enabled {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for sl in world.query::<&SpotLight>().iter(world) {
|
||||
if sl.shadows_enabled {
|
||||
if sl.shadow_maps_enabled {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ pub fn clear_viewport_camera_stack(commands: &mut Commands, entity: Entity) {
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct ViewportFxSnapshot {
|
||||
pub has_stack: bool,
|
||||
pub has_atmosphere: bool,
|
||||
pub has_atmosphere_settings: bool,
|
||||
pub has_tonemapping: bool,
|
||||
pub has_bloom: bool,
|
||||
pub has_ssao: bool,
|
||||
@@ -156,7 +156,7 @@ pub fn sync_viewport_camera_stack(
|
||||
caps,
|
||||
solari_stats,
|
||||
mediums,
|
||||
snap.has_atmosphere,
|
||||
snap.has_atmosphere_settings,
|
||||
snap.has_tonemapping,
|
||||
snap.has_bloom,
|
||||
snap.has_ssao,
|
||||
@@ -203,6 +203,19 @@ pub fn sync_viewport_camera_stack(
|
||||
}
|
||||
|
||||
/// Builds a [`ViewportFxSnapshot`] from an entity's current components.
|
||||
pub fn snapshot_viewport_fx(entity: Entity, world: &World) -> ViewportFxSnapshot {
|
||||
ViewportFxSnapshot {
|
||||
has_stack: world.get::<ProjectRenderCamera>(entity).is_some(),
|
||||
has_atmosphere_settings: world.get::<AtmosphereSettings>(entity).is_some(),
|
||||
has_tonemapping: world.get::<Tonemapping>(entity).is_some(),
|
||||
has_bloom: world.get::<Bloom>(entity).is_some(),
|
||||
has_ssao: world.get::<ScreenSpaceAmbientOcclusion>(entity).is_some(),
|
||||
has_taa: world.get::<TemporalAntiAliasing>(entity).is_some(),
|
||||
has_hdr: world.get::<Hdr>(entity).is_some(),
|
||||
has_auto_exposure: world.get::<AutoExposure>(entity).is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -230,16 +243,3 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn snapshot_viewport_fx(entity: Entity, world: &World) -> ViewportFxSnapshot {
|
||||
ViewportFxSnapshot {
|
||||
has_stack: world.get::<ProjectRenderCamera>(entity).is_some(),
|
||||
has_atmosphere: world.get::<Atmosphere>(entity).is_some(),
|
||||
has_tonemapping: world.get::<Tonemapping>(entity).is_some(),
|
||||
has_bloom: world.get::<Bloom>(entity).is_some(),
|
||||
has_ssao: world.get::<ScreenSpaceAmbientOcclusion>(entity).is_some(),
|
||||
has_taa: world.get::<TemporalAntiAliasing>(entity).is_some(),
|
||||
has_hdr: world.get::<Hdr>(entity).is_some(),
|
||||
has_auto_exposure: world.get::<AutoExposure>(entity).is_some(),
|
||||
}
|
||||
}
|
||||
@@ -252,6 +252,10 @@ pub fn resolve_active_camera_render_profile(
|
||||
}
|
||||
|
||||
/// Bevy system: updates [`ActiveCameraRenderProfile`] and [`ActiveVolumeContribution`].
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy systems expose independent render resources, queries, and local state"
|
||||
)]
|
||||
pub fn sync_active_camera_render_profile(
|
||||
mut commands: Commands,
|
||||
settings: Res<ProjectSettings>,
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn spawn_sun(
|
||||
ProjectSun,
|
||||
DirectionalLight {
|
||||
illuminance: rendering.sun_illuminance,
|
||||
shadows_enabled: !has_scene_sun_override(&scene_suns),
|
||||
shadow_maps_enabled: !has_scene_sun_override(&scene_suns),
|
||||
..default()
|
||||
},
|
||||
Visibility::default(),
|
||||
@@ -44,7 +44,7 @@ pub fn sync_project_sun_visibility(
|
||||
) {
|
||||
let scene_override = has_scene_sun_override(&scene_suns);
|
||||
for (mut sun, mut visibility) in &mut project_suns {
|
||||
sun.shadows_enabled = !scene_override;
|
||||
sun.shadow_maps_enabled = !scene_override;
|
||||
*visibility = if scene_override {
|
||||
Visibility::Hidden
|
||||
} else {
|
||||
@@ -106,7 +106,7 @@ pub fn sync_project_sun_from_settings(
|
||||
let illuminance = settings.rendering.sun_illuminance;
|
||||
for (mut sun, mut visibility) in &mut project_suns {
|
||||
sun.illuminance = illuminance;
|
||||
sun.shadows_enabled = !scene_override;
|
||||
sun.shadow_maps_enabled = !scene_override;
|
||||
*visibility = if scene_override {
|
||||
Visibility::Hidden
|
||||
} else {
|
||||
|
||||
@@ -107,7 +107,8 @@ pub const FORBIDDEN_SAVED_COMPONENT_MARKERS: &[&str] = &[
|
||||
"bevy_mesh::MeshMaterial3d",
|
||||
"avian3d::RigidBody",
|
||||
"avian3d::Collider",
|
||||
"bevy_scene::SceneRoot",
|
||||
"bevy_world_serialization::components::WorldAssetRoot",
|
||||
"bevy_world_serialization::components::DynamicWorldRoot",
|
||||
"bevy_render::visibility::ComputedVisibility",
|
||||
];
|
||||
|
||||
@@ -189,7 +190,7 @@ mod tests {
|
||||
},
|
||||
),
|
||||
}))";
|
||||
let migrated = migrate_scene_text(&v1).unwrap();
|
||||
let migrated = migrate_scene_text(v1).unwrap();
|
||||
assert!(migrated.contains("ActorKind"));
|
||||
assert!(migrated.contains("StaticMesh"));
|
||||
}
|
||||
|
||||
@@ -173,9 +173,7 @@ fn fix_directional_intensity(block: &str) -> String {
|
||||
};
|
||||
let after = &block[intensity_idx + "intensity:".len()..];
|
||||
let trimmed = after.trim_start();
|
||||
let end = trimmed
|
||||
.find(|c: char| c == ',' || c == ')')
|
||||
.unwrap_or(trimmed.len());
|
||||
let end = trimmed.find([',', ')']).unwrap_or(trimmed.len());
|
||||
let value_str = trimmed[..end].trim();
|
||||
let Ok(value) = value_str.parse::<f32>() else {
|
||||
return block.to_string();
|
||||
|
||||
@@ -245,9 +245,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn effective_auto_exposure_requires_hdr_and_compute() {
|
||||
let mut profile = ActiveCameraRenderProfile::default();
|
||||
profile.exposure_mode = ExposureMode::Auto;
|
||||
profile.hdr = true;
|
||||
let mut profile = ActiveCameraRenderProfile {
|
||||
exposure_mode: ExposureMode::Auto,
|
||||
hdr: true,
|
||||
..Default::default()
|
||||
};
|
||||
let caps = RenderingCapabilities {
|
||||
auto_exposure_supported: true,
|
||||
..Default::default()
|
||||
|
||||
@@ -11,9 +11,7 @@ use crate::{
|
||||
|
||||
/// One-shot deterministic kind from authoring components (scene migration only).
|
||||
pub fn infer_actor_kind(entity: EntityRef<'_>) -> Option<ActorKind> {
|
||||
if entity.get::<LevelObject>().is_none() {
|
||||
return None;
|
||||
}
|
||||
entity.get::<LevelObject>()?;
|
||||
if entity.get::<PlayerSpawn>().is_some() {
|
||||
return Some(ActorKind::PlayerSpawn);
|
||||
}
|
||||
|
||||
@@ -125,6 +125,20 @@ pub fn validate_brush(brush: &BrushDesc) -> BrushValidationReport {
|
||||
"Face UV scale is zero or non-finite.",
|
||||
);
|
||||
}
|
||||
if !face.uv_offset.is_finite() {
|
||||
report.push(
|
||||
BrushDiagnosticSeverity::Warning,
|
||||
Some(face.id.clone()),
|
||||
"Face UV offset is non-finite.",
|
||||
);
|
||||
}
|
||||
if !face.uv_rotation.is_finite() {
|
||||
report.push(
|
||||
BrushDiagnosticSeverity::Warning,
|
||||
Some(face.id.clone()),
|
||||
"Face UV rotation is non-finite.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let non_manifold_edges = count_non_manifold_edges(brush);
|
||||
@@ -547,12 +561,26 @@ mod tests {
|
||||
fn reports_uv_warnings_without_invalidating_brush() {
|
||||
let mut brush = BrushDesc::default();
|
||||
brush.faces[0].uv_scale = Vec2::ZERO;
|
||||
brush.faces[1].uv_offset = Vec2::new(f32::NAN, 0.0);
|
||||
brush.faces[2].uv_rotation = f32::INFINITY;
|
||||
let report = validate_brush(&brush);
|
||||
assert!(report.is_valid());
|
||||
assert_eq!(
|
||||
report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.filter(|diagnostic| diagnostic.severity == BrushDiagnosticSeverity::Warning)
|
||||
.count(),
|
||||
3
|
||||
);
|
||||
assert!(report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|diagnostic| diagnostic.severity == BrushDiagnosticSeverity::Warning));
|
||||
.any(|diagnostic| diagnostic.message.contains("UV offset")));
|
||||
assert!(report
|
||||
.diagnostics
|
||||
.iter()
|
||||
.any(|diagnostic| diagnostic.message.contains("UV rotation")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -765,7 +765,7 @@ impl Default for MaterialDesc {
|
||||
}
|
||||
|
||||
/// Reflectable reference to an imported 3D model scene (glTF/GLB or FBX).
|
||||
/// Hydration turns this into a `SceneRoot` on the entity.
|
||||
/// Hydration turns this into a `WorldAssetRoot` on the entity.
|
||||
#[derive(Component, Reflect, Default, Debug, Clone, Serialize, Deserialize)]
|
||||
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct ModelRef {
|
||||
@@ -790,7 +790,7 @@ impl ModelRef {
|
||||
}
|
||||
|
||||
/// Reflectable reference to a saved `.scn.ron` dynamic scene under `assets/`.
|
||||
/// Hydration turns this into a `DynamicSceneRoot`.
|
||||
/// Hydration turns this into a `DynamicWorldRoot`.
|
||||
#[derive(Component, Reflect, Default, Debug, Clone, Serialize, Deserialize)]
|
||||
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct PrefabRef {
|
||||
@@ -1256,9 +1256,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn point_spot_lumen_max_covers_bevy_cinema_reference() {
|
||||
assert!(
|
||||
super::AUTHORING_POINT_SPOT_LUMENS_MAX >= light_consts::lumens::VERY_LARGE_CINEMA_LIGHT
|
||||
);
|
||||
const {
|
||||
assert!(
|
||||
super::AUTHORING_POINT_SPOT_LUMENS_MAX
|
||||
>= light_consts::lumens::VERY_LARGE_CINEMA_LIGHT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -67,6 +67,10 @@ pub fn hydrate_brushes(
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "hydration keeps Bevy asset stores and authored brush inputs explicit"
|
||||
)]
|
||||
pub fn spawn_brush_mesh(
|
||||
commands: &mut Commands,
|
||||
asset_server: &AssetServer,
|
||||
@@ -243,7 +247,12 @@ fn append_face(
|
||||
for vertex in &face.vertices {
|
||||
positions.push([vertex.x, vertex.y, vertex.z]);
|
||||
normals.push([normal.x, normal.y, normal.z]);
|
||||
let uv = Vec2::new(vertex.dot(u_axis), vertex.dot(v_axis)) * face.uv_scale + face.uv_offset;
|
||||
let uv = transform_face_uv(
|
||||
Vec2::new(vertex.dot(u_axis), vertex.dot(v_axis)),
|
||||
face.uv_scale,
|
||||
face.uv_rotation,
|
||||
face.uv_offset,
|
||||
);
|
||||
uvs.push([uv.x, uv.y]);
|
||||
}
|
||||
|
||||
@@ -262,6 +271,29 @@ fn append_face(
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn transform_face_uv(base: Vec2, scale: Vec2, rotation_degrees: f32, offset: Vec2) -> Vec2 {
|
||||
let scale = if scale.is_finite() { scale } else { Vec2::ONE };
|
||||
let rotation_degrees = if rotation_degrees.is_finite() {
|
||||
rotation_degrees
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let offset = if offset.is_finite() {
|
||||
offset
|
||||
} else {
|
||||
Vec2::ZERO
|
||||
};
|
||||
let scaled = base * scale;
|
||||
if rotation_degrees == 0.0 {
|
||||
return scaled + offset;
|
||||
}
|
||||
let (sin, cos) = rotation_degrees.to_radians().sin_cos();
|
||||
Vec2::new(
|
||||
scaled.x * cos - scaled.y * sin,
|
||||
scaled.x * sin + scaled.y * cos,
|
||||
) + offset
|
||||
}
|
||||
|
||||
fn face_axes(normal: Vec3) -> (Vec3, Vec3) {
|
||||
let tangent_seed = if normal.y.abs() > 0.9 {
|
||||
Vec3::X
|
||||
@@ -319,6 +351,27 @@ mod tests {
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brush_face_uv_transform_applies_scale_rotation_and_offset() {
|
||||
let uv = transform_face_uv(
|
||||
Vec2::new(2.0, 1.0),
|
||||
Vec2::new(2.0, 3.0),
|
||||
90.0,
|
||||
Vec2::new(0.25, -0.5),
|
||||
);
|
||||
|
||||
assert!((uv.x + 2.75).abs() < 0.0001);
|
||||
assert!((uv.y - 3.5).abs() < 0.0001);
|
||||
|
||||
let sanitized = transform_face_uv(
|
||||
Vec2::new(2.0, 1.0),
|
||||
Vec2::new(f32::NAN, 3.0),
|
||||
f32::INFINITY,
|
||||
Vec2::new(0.25, f32::NAN),
|
||||
);
|
||||
assert_eq!(sanitized, Vec2::new(2.0, 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_brush_returns_none() {
|
||||
let mut brush = BrushDesc::default();
|
||||
|
||||
@@ -77,6 +77,10 @@ pub(crate) fn normalized_directional_lux(intensity: f32) -> f32 {
|
||||
|
||||
/// Re-applies runtime lights when authoring [`LightDesc`] exists but hydration was stripped.
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "Bevy systems expose independent resource and query parameters"
|
||||
)]
|
||||
pub fn reconcile_missing_runtime_lights(
|
||||
mut commands: Commands,
|
||||
settings: Res<settings::ProjectSettings>,
|
||||
@@ -140,7 +144,7 @@ pub(crate) fn insert_light_from_desc(
|
||||
color,
|
||||
intensity: light.intensity,
|
||||
range: light.range,
|
||||
shadows_enabled: light.shadows,
|
||||
shadow_maps_enabled: light.shadows,
|
||||
..default()
|
||||
},
|
||||
Visibility::Visible,
|
||||
@@ -152,7 +156,7 @@ pub(crate) fn insert_light_from_desc(
|
||||
color,
|
||||
intensity: light.intensity,
|
||||
range: light.range,
|
||||
shadows_enabled: light.shadows,
|
||||
shadow_maps_enabled: light.shadows,
|
||||
outer_angle: light.outer_angle_deg.to_radians(),
|
||||
inner_angle: light.inner_angle_deg.to_radians(),
|
||||
..default()
|
||||
@@ -165,7 +169,7 @@ pub(crate) fn insert_light_from_desc(
|
||||
DirectionalLight {
|
||||
color,
|
||||
illuminance: normalized_directional_lux(light.intensity),
|
||||
shadows_enabled: light.shadows,
|
||||
shadow_maps_enabled: light.shadows,
|
||||
..default()
|
||||
},
|
||||
Visibility::Visible,
|
||||
@@ -192,7 +196,7 @@ mod tests {
|
||||
let rendering = RenderingSettings::default();
|
||||
let spot = LightDesc::for_kind(AuthoringLightKind::Spot);
|
||||
{
|
||||
let mut commands = Commands::new(&mut queue, &mut world);
|
||||
let mut commands = Commands::new(&mut queue, &world);
|
||||
let mut entity_commands = commands.entity(entity);
|
||||
insert_light_from_desc(&mut entity_commands, &spot, &rendering);
|
||||
}
|
||||
@@ -202,7 +206,7 @@ mod tests {
|
||||
let point = LightDesc::for_kind(AuthoringLightKind::Point);
|
||||
queue = CommandQueue::default();
|
||||
{
|
||||
let mut commands = Commands::new(&mut queue, &mut world);
|
||||
let mut commands = Commands::new(&mut queue, &world);
|
||||
let mut entity_commands = commands.entity(entity);
|
||||
strip_light_components(&mut entity_commands);
|
||||
insert_light_from_desc(&mut entity_commands, &point, &rendering);
|
||||
@@ -221,7 +225,7 @@ mod tests {
|
||||
let mut light = LightDesc::for_kind(AuthoringLightKind::Directional);
|
||||
light.shadows = true;
|
||||
{
|
||||
let mut commands = Commands::new(&mut queue, &mut world);
|
||||
let mut commands = Commands::new(&mut queue, &world);
|
||||
let mut entity_commands = commands.entity(entity);
|
||||
insert_light_from_desc(&mut entity_commands, &light, &rendering);
|
||||
}
|
||||
@@ -239,10 +243,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn scene_directional_cascades_match_project_shadow_settings() {
|
||||
let mut rendering = RenderingSettings::default();
|
||||
rendering.shadow_cascades = 3;
|
||||
rendering.shadow_first_cascade = 12.0;
|
||||
rendering.shadow_max_distance = 400.0;
|
||||
let rendering = RenderingSettings {
|
||||
shadow_cascades: 3,
|
||||
shadow_first_cascade: 12.0,
|
||||
shadow_max_distance: 400.0,
|
||||
..Default::default()
|
||||
};
|
||||
let config = cascade_config_from_rendering(&rendering);
|
||||
let expected = cascade_config_from_rendering(&rendering);
|
||||
assert_eq!(config.bounds, expected.bounds);
|
||||
@@ -257,7 +263,7 @@ mod tests {
|
||||
let spot_entity = world.spawn(LevelObject).id();
|
||||
let rendering = RenderingSettings::default();
|
||||
{
|
||||
let mut commands = Commands::new(&mut queue, &mut world);
|
||||
let mut commands = Commands::new(&mut queue, &world);
|
||||
insert_light_from_desc(
|
||||
&mut commands.entity(point_entity),
|
||||
&LightDesc::for_kind(AuthoringLightKind::Point),
|
||||
|
||||
@@ -79,9 +79,11 @@ mod tests {
|
||||
let mut app = App::new();
|
||||
app.add_plugins((MinimalPlugins, AssetPlugin::default()));
|
||||
let asset_server = app.world().resource::<AssetServer>();
|
||||
let mut desc = MaterialDesc::default();
|
||||
desc.emissive_color = ColorDesc::srgb(0.5, 0.25, 1.0);
|
||||
desc.emissive_intensity = 1000.0;
|
||||
let desc = MaterialDesc {
|
||||
emissive_color: ColorDesc::srgb(0.5, 0.25, 1.0),
|
||||
emissive_intensity: 1000.0,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let material = material_from_desc(asset_server, &desc);
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ use static_meshes::{
|
||||
hydrate_static_mesh_renderers, spawn_static_mesh_parts, HydratedStaticMeshPart,
|
||||
StaticMeshArtifactCache,
|
||||
};
|
||||
use visibility::{init_editor_visibility_on_spawn, sync_editor_visibility};
|
||||
use visibility::{
|
||||
ensure_level_object_visibility_hierarchy, init_editor_visibility_on_spawn,
|
||||
sync_editor_visibility, visibility_from_editor,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
inspector_component_active, BrushDesc, ColliderDesc, EditorVisibility, InspectorOrder,
|
||||
@@ -61,12 +64,21 @@ impl Plugin for HydrationPlugin {
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
(sync_editor_visibility, init_editor_visibility_on_spawn).chain(),
|
||||
(
|
||||
ensure_level_object_visibility_hierarchy,
|
||||
sync_editor_visibility,
|
||||
init_editor_visibility_on_spawn,
|
||||
)
|
||||
.chain(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the full hydration chain immediately (e.g. after scene load in the editor).
|
||||
#[expect(
|
||||
clippy::type_complexity,
|
||||
reason = "exclusive hydration snapshots several authored component combinations"
|
||||
)]
|
||||
pub fn flush_level_object_hydration(world: &mut World) {
|
||||
if !world.contains_resource::<StaticMeshArtifactCache>() {
|
||||
world.insert_resource(StaticMeshArtifactCache::default());
|
||||
@@ -227,8 +239,9 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
)> = SystemState::new(world);
|
||||
|
||||
{
|
||||
let (mut commands, asset_server, mut meshes, mut materials, mut artifact_cache) =
|
||||
state.get_mut(world);
|
||||
let (mut commands, asset_server, mut meshes, mut materials, mut artifact_cache) = state
|
||||
.get_mut(world)
|
||||
.expect("hydrate_level_objects system params should be valid");
|
||||
|
||||
for (entity, primitive) in primitives {
|
||||
let mesh = meshes.add(primitive_mesh(&primitive));
|
||||
@@ -285,12 +298,21 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
state.apply(world);
|
||||
|
||||
for (entity, editor) in visibility_targets {
|
||||
let visibility = visibility_from_editor(editor);
|
||||
if let Some(mut vis) = world.get_mut::<Visibility>(entity) {
|
||||
*vis = if editor.visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
*vis = visibility;
|
||||
} else if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(visibility);
|
||||
}
|
||||
if world.get::<InheritedVisibility>(entity).is_none() {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(InheritedVisibility::default());
|
||||
}
|
||||
}
|
||||
if world.get::<ViewVisibility>(entity).is_none() {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(ViewVisibility::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,8 +322,8 @@ mod tests {
|
||||
use super::flush_level_object_hydration;
|
||||
use super::strip::strip_hydrated_entity;
|
||||
use crate::{
|
||||
AuthoringLightKind, ColorDesc, InspectorOrder, LevelObject, LightDesc, MaterialDesc,
|
||||
Primitive, COMPONENT_LIGHT_DESC,
|
||||
AuthoringLightKind, ColorDesc, EditorVisibility, InspectorOrder, LevelObject, LightDesc,
|
||||
MaterialDesc, Primitive, COMPONENT_LIGHT_DESC,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
@@ -324,6 +346,29 @@ mod tests {
|
||||
assert!(app.world().get::<PointLight>(entity).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_hydration_initializes_level_object_visibility_hierarchy() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.add_plugins(AssetPlugin::default());
|
||||
app.add_plugins(bevy::pbr::MaterialPlugin::<StandardMaterial>::default());
|
||||
app.init_asset::<Mesh>();
|
||||
|
||||
let entity = app
|
||||
.world_mut()
|
||||
.spawn((LevelObject, EditorVisibility { visible: false }))
|
||||
.id();
|
||||
|
||||
flush_level_object_hydration(app.world_mut());
|
||||
|
||||
assert_eq!(
|
||||
app.world().get::<Visibility>(entity),
|
||||
Some(&Visibility::Hidden)
|
||||
);
|
||||
assert!(app.world().get::<InheritedVisibility>(entity).is_some());
|
||||
assert!(app.world().get::<ViewVisibility>(entity).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flush_hydration_skips_point_light_when_solari_is_active() {
|
||||
let mut app = App::new();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Imported model scenes from [`ModelRef`] authoring data.
|
||||
|
||||
use bevy::gltf::GltfAssetLabel;
|
||||
use bevy::prelude::WorldAssetRoot;
|
||||
use bevy::prelude::*;
|
||||
use bevy::scene::SceneRoot;
|
||||
|
||||
use crate::{asset_server_path, LevelObject, ModelRef};
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn hydrate_models(
|
||||
despawn_generated_children(&mut commands, entity, child_list);
|
||||
}
|
||||
|
||||
commands.entity(entity).remove::<SceneRoot>();
|
||||
commands.entity(entity).remove::<WorldAssetRoot>();
|
||||
|
||||
let path = asset_server_path(&model.path);
|
||||
let handle = if path.ends_with(".fbx") {
|
||||
@@ -31,6 +31,6 @@ pub fn hydrate_models(
|
||||
} else {
|
||||
asset_server.load(GltfAssetLabel::Scene(model.scene_index).from_asset(path))
|
||||
};
|
||||
commands.entity(entity).insert(SceneRoot(handle));
|
||||
commands.entity(entity).insert(WorldAssetRoot(handle));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Prefab scene roots from [`PrefabRef`] / [`PrefabInstance`] authoring data.
|
||||
|
||||
use bevy::prelude::DynamicWorldRoot;
|
||||
use bevy::prelude::*;
|
||||
use bevy::scene::DynamicSceneRoot;
|
||||
|
||||
use crate::{LevelObject, PrefabInstance, PrefabRef};
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn hydrate_prefabs(
|
||||
>,
|
||||
) {
|
||||
for (entity, prefab) in &prefabs {
|
||||
commands.entity(entity).insert(DynamicSceneRoot(
|
||||
commands.entity(entity).insert(DynamicWorldRoot(
|
||||
asset_server.load(asset_server_path(&prefab.path)),
|
||||
));
|
||||
}
|
||||
@@ -37,7 +37,7 @@ pub fn hydrate_prefabs(
|
||||
let path = asset_server_path(&instance.source_path);
|
||||
commands.entity(entity).insert((
|
||||
PrefabRef::new(instance.source_path.clone()),
|
||||
DynamicSceneRoot(asset_server.load(path)),
|
||||
DynamicWorldRoot(asset_server.load(path)),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -202,6 +202,10 @@ pub fn hydrate_static_mesh_renderers(
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "hydration keeps Bevy asset stores and authored mesh inputs explicit"
|
||||
)]
|
||||
pub fn spawn_static_mesh_parts(
|
||||
commands: &mut Commands,
|
||||
asset_server: &AssetServer,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use bevy::scene::{DynamicSceneRoot, SceneRoot};
|
||||
|
||||
/// Strips hydrated components via [`EntityWorldMut`] (e.g. before scene save).
|
||||
pub fn strip_hydrated_entity(entity: &mut EntityWorldMut<'_>) {
|
||||
@@ -12,8 +11,8 @@ pub fn strip_hydrated_entity(entity: &mut EntityWorldMut<'_>) {
|
||||
.remove::<PointLight>()
|
||||
.remove::<SpotLight>()
|
||||
.remove::<DirectionalLight>()
|
||||
.remove::<SceneRoot>()
|
||||
.remove::<DynamicSceneRoot>()
|
||||
.remove::<WorldAssetRoot>()
|
||||
.remove::<DynamicWorldRoot>()
|
||||
.remove::<RigidBody>()
|
||||
.remove::<Collider>();
|
||||
}
|
||||
@@ -26,13 +25,13 @@ pub fn strip_hydrated(entity_commands: &mut EntityCommands<'_>) {
|
||||
.remove::<PointLight>()
|
||||
.remove::<SpotLight>()
|
||||
.remove::<DirectionalLight>()
|
||||
.remove::<SceneRoot>()
|
||||
.remove::<DynamicSceneRoot>()
|
||||
.remove::<WorldAssetRoot>()
|
||||
.remove::<DynamicWorldRoot>()
|
||||
.remove::<RigidBody>()
|
||||
.remove::<Collider>();
|
||||
}
|
||||
|
||||
/// Despawns all child entities (e.g. prior `SceneRoot` instance hierarchy).
|
||||
/// Despawns all child entities (e.g. prior `WorldAssetRoot` instance hierarchy).
|
||||
pub fn despawn_generated_children(commands: &mut Commands, entity: Entity, children: &Children) {
|
||||
for child in children.iter() {
|
||||
commands.entity(child).despawn();
|
||||
|
||||
@@ -3,6 +3,41 @@
|
||||
use crate::{EditorVisibility, LevelObject};
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[expect(
|
||||
clippy::type_complexity,
|
||||
reason = "the query mirrors Bevy's three visibility hierarchy components"
|
||||
)]
|
||||
pub fn ensure_level_object_visibility_hierarchy(
|
||||
mut commands: Commands,
|
||||
query: Query<
|
||||
(
|
||||
Entity,
|
||||
&EditorVisibility,
|
||||
Option<&Visibility>,
|
||||
Option<&InheritedVisibility>,
|
||||
Option<&ViewVisibility>,
|
||||
),
|
||||
With<LevelObject>,
|
||||
>,
|
||||
) {
|
||||
for (entity, editor, visibility, inherited_visibility, view_visibility) in &query {
|
||||
let mut entity_commands = commands.entity(entity);
|
||||
if visibility.is_none() {
|
||||
entity_commands.insert(visibility_from_editor(*editor));
|
||||
}
|
||||
if inherited_visibility.is_none() {
|
||||
entity_commands.insert(InheritedVisibility::default());
|
||||
}
|
||||
if view_visibility.is_none() {
|
||||
entity_commands.insert(ViewVisibility::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::type_complexity,
|
||||
reason = "the query expresses Bevy change detection at the system boundary"
|
||||
)]
|
||||
pub fn sync_editor_visibility(
|
||||
mut query: Query<
|
||||
(&EditorVisibility, &mut Visibility),
|
||||
@@ -13,14 +48,14 @@ pub fn sync_editor_visibility(
|
||||
>,
|
||||
) {
|
||||
for (editor, mut visibility) in query.iter_mut() {
|
||||
*visibility = if editor.visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
*visibility = visibility_from_editor(*editor);
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::type_complexity,
|
||||
reason = "the query expresses Bevy spawn detection at the system boundary"
|
||||
)]
|
||||
pub fn init_editor_visibility_on_spawn(
|
||||
mut query: Query<
|
||||
(&EditorVisibility, &mut Visibility),
|
||||
@@ -32,10 +67,39 @@ pub fn init_editor_visibility_on_spawn(
|
||||
>,
|
||||
) {
|
||||
for (editor, mut visibility) in query.iter_mut() {
|
||||
*visibility = if editor.visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
*visibility = visibility_from_editor(*editor);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visibility_from_editor(editor: EditorVisibility) -> Visibility {
|
||||
if editor.visible {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ensure_level_object_visibility_hierarchy;
|
||||
use crate::{EditorVisibility, LevelObject};
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn level_object_visibility_hierarchy_is_inserted_for_generated_children() {
|
||||
let mut app = App::new();
|
||||
app.add_systems(Update, ensure_level_object_visibility_hierarchy);
|
||||
|
||||
let entity = app
|
||||
.world_mut()
|
||||
.spawn((LevelObject, EditorVisibility { visible: false }))
|
||||
.id();
|
||||
|
||||
app.update();
|
||||
|
||||
let world = app.world();
|
||||
assert_eq!(world.get::<Visibility>(entity), Some(&Visibility::Hidden));
|
||||
assert!(world.get::<InheritedVisibility>(entity).is_some());
|
||||
assert!(world.get::<ViewVisibility>(entity).is_some());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user