This commit is contained in:
1 parent
0e7aed40f1
commit
0ce43fc399
19 files changed
+1180
-127
No files matched your search
@@ -15,6 +15,9 @@ use crate::project_io::ProjectWorkspace;
|
||||
use crate::scene_io::{SceneIo, SceneIoEventSeverity};
|
||||
use crate::selection::SelectedEntity;
|
||||
use crate::ui::UiState;
|
||||
use crate::viewport::collider_diagnostics::{
|
||||
ColliderDiagnosticSeverity, ColliderDiagnosticsState, ColliderOverlayStatus,
|
||||
};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct DiagnosticsPanel {
|
||||
@@ -138,6 +141,9 @@ pub fn diagnostics_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
collider_diagnostics_ui(world, ui);
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
ui.strong("Support bundle");
|
||||
@@ -193,6 +199,73 @@ pub fn diagnostics_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
ui.small("BRP is enabled on the editor for external tooling.");
|
||||
}
|
||||
|
||||
fn collider_diagnostics_ui(world: &mut World, ui: &mut egui::Ui) {
|
||||
let Some(state) = world.get_resource::<ColliderDiagnosticsState>() else {
|
||||
return;
|
||||
};
|
||||
let mut rows = state.entries.values().cloned().collect::<Vec<_>>();
|
||||
rows.sort_by(|left, right| left.actor_name.cmp(&right.actor_name));
|
||||
let valid = state.valid_actors;
|
||||
let disabled = state.disabled_actors;
|
||||
let warnings = state.warning_actors;
|
||||
let errors = state.error_actors;
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.strong("Collider health");
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(125, 210, 145),
|
||||
format!("{valid} ready"),
|
||||
);
|
||||
if disabled > 0 {
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(143, 151, 163),
|
||||
format!("{disabled} disabled"),
|
||||
);
|
||||
}
|
||||
if warnings > 0 {
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(242, 173, 72),
|
||||
format!("{warnings} warning"),
|
||||
);
|
||||
}
|
||||
if errors > 0 {
|
||||
ui.colored_label(
|
||||
egui::Color32::from_rgb(244, 91, 99),
|
||||
format!("{errors} invalid"),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
for row in rows.into_iter().filter(|row| {
|
||||
matches!(
|
||||
row.overlay_status,
|
||||
ColliderOverlayStatus::Warning | ColliderOverlayStatus::Error
|
||||
)
|
||||
}) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let color = match row.overlay_status {
|
||||
ColliderOverlayStatus::Error => egui::Color32::from_rgb(244, 91, 99),
|
||||
_ => egui::Color32::from_rgb(242, 173, 72),
|
||||
};
|
||||
ui.colored_label(color, row.shape_label);
|
||||
ui.label(&row.actor_name);
|
||||
if ui.small_button("Select").clicked() {
|
||||
world.resource_mut::<SelectedEntity>().0 = Some(row.entity);
|
||||
world
|
||||
.resource_mut::<UiState>()
|
||||
.selected_entities
|
||||
.select_replace(row.entity);
|
||||
}
|
||||
});
|
||||
for diagnostic in &row.diagnostics {
|
||||
if diagnostic.severity == ColliderDiagnosticSeverity::Info {
|
||||
continue;
|
||||
}
|
||||
ui.small(format!("{}: {}", diagnostic.code, diagnostic.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn brush_diagnostics_window(world: &mut World, ctx: &egui::Context, open: &mut bool) {
|
||||
if !*open {
|
||||
return;
|
||||
|
||||
@@ -44,6 +44,9 @@ use crate::ui::theme::{
|
||||
};
|
||||
use crate::ui::widgets::{icon_button_small, phosphor_icon, phosphor_icon_text};
|
||||
use crate::viewport::brush_edit::{BrushElementKey, BrushElementSelection};
|
||||
use crate::viewport::collider_diagnostics::{
|
||||
diagnose_collider, ColliderDiagnosticSeverity, ColliderOverlayStatus,
|
||||
};
|
||||
|
||||
use super::component_registry::{
|
||||
EditorComponentCategory, EditorComponentDescriptor, EditorComponentRegistry,
|
||||
@@ -4213,6 +4216,7 @@ fn rigid_body_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
|
||||
fn collider_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let mesh_candidates = static_mesh_asset_ref_candidates(world, AssetRefCandidateKind::Mesh);
|
||||
let diagnostic_entry = diagnose_collider(world, entity);
|
||||
let Some(mut collider) = world.get::<ColliderDesc>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
@@ -4235,13 +4239,60 @@ fn collider_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
ComponentCardOptions::removable(COMPONENT_COLLIDER_DESC, "Collider", icons::SELECTION),
|
||||
);
|
||||
let card_response = component_card(ui, &card, |ui| {
|
||||
if let Some(entry) = diagnostic_entry.as_ref() {
|
||||
let (label, color) = match entry.overlay_status {
|
||||
ColliderOverlayStatus::Valid => ("Ready", egui::Color32::from_rgb(112, 210, 144)),
|
||||
ColliderOverlayStatus::Trigger => {
|
||||
("Trigger", egui::Color32::from_rgb(86, 195, 235))
|
||||
}
|
||||
ColliderOverlayStatus::Disabled => {
|
||||
("Disabled", egui::Color32::from_rgb(143, 151, 163))
|
||||
}
|
||||
ColliderOverlayStatus::Warning => {
|
||||
("Warning", egui::Color32::from_rgb(242, 173, 72))
|
||||
}
|
||||
ColliderOverlayStatus::Error => ("Invalid", egui::Color32::from_rgb(244, 91, 99)),
|
||||
};
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.colored_label(color, egui::RichText::new(label).strong());
|
||||
ui.label(egui::RichText::new(entry.shape_label).color(TEXT_DIM));
|
||||
if entry.runtime_ready {
|
||||
ui.label(egui::RichText::new("Hydrated").color(TEXT_MUTED).small());
|
||||
}
|
||||
});
|
||||
for diagnostic in &entry.diagnostics {
|
||||
let color = match diagnostic.severity {
|
||||
ColliderDiagnosticSeverity::Info => TEXT_MUTED,
|
||||
ColliderDiagnosticSeverity::Warning => egui::Color32::from_rgb(242, 173, 72),
|
||||
ColliderDiagnosticSeverity::Error => egui::Color32::from_rgb(244, 91, 99),
|
||||
};
|
||||
ui.label(
|
||||
egui::RichText::new(&diagnostic.message)
|
||||
.color(color)
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(&diagnostic.repair)
|
||||
.color(TEXT_MUTED)
|
||||
.small(),
|
||||
);
|
||||
}
|
||||
if entry.highest_severity() == Some(ColliderDiagnosticSeverity::Error)
|
||||
&& ui.small_button("Reset shape").clicked()
|
||||
{
|
||||
collider.shape = ColliderShapeDesc::default();
|
||||
collider.enabled = true;
|
||||
changed = true;
|
||||
}
|
||||
ui.add_space(2.0);
|
||||
}
|
||||
property_row(ui, "Mode", |ui| {
|
||||
changed |= ui.checkbox(&mut collider.enabled, "Enabled").changed();
|
||||
changed |= ui.checkbox(&mut collider.is_trigger, "Trigger").changed();
|
||||
});
|
||||
property_row(ui, "Shape", |ui| {
|
||||
let mut shape_kind = collider_shape_kind(&collider.shape);
|
||||
egui::ComboBox::from_id_salt("collider_shape_kind")
|
||||
egui::ComboBox::from_id_salt(("collider_shape_kind", entity))
|
||||
.selected_text(shape_kind)
|
||||
.show_ui(ui, |ui| {
|
||||
for label in ["Box", "Sphere", "Capsule", "Static Mesh"] {
|
||||
@@ -4251,15 +4302,8 @@ fn collider_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
}
|
||||
});
|
||||
if shape_kind != collider_shape_kind(&collider.shape) {
|
||||
collider.shape = match shape_kind {
|
||||
"Sphere" => ColliderShapeDesc::Sphere { radius: 0.5 },
|
||||
"Capsule" => ColliderShapeDesc::Capsule {
|
||||
radius: 0.5,
|
||||
height: 1.0,
|
||||
},
|
||||
"Static Mesh" => ColliderShapeDesc::static_mesh(renderer_meshes.clone()),
|
||||
_ => ColliderShapeDesc::default(),
|
||||
};
|
||||
collider.shape =
|
||||
convert_collider_shape(&collider.shape, shape_kind, renderer_meshes.clone());
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
@@ -4327,12 +4371,48 @@ fn collider_shape_kind(shape: &ColliderShapeDesc) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_collider_shape(
|
||||
previous: &ColliderShapeDesc,
|
||||
shape_kind: &str,
|
||||
renderer_meshes: Vec<EditorAssetRef>,
|
||||
) -> ColliderShapeDesc {
|
||||
let dimensions = match previous {
|
||||
ColliderShapeDesc::Cuboid {
|
||||
x_length,
|
||||
y_length,
|
||||
z_length,
|
||||
} => Vec3::new(*x_length, *y_length, *z_length),
|
||||
ColliderShapeDesc::Sphere { radius } => Vec3::splat(*radius * 2.0),
|
||||
ColliderShapeDesc::Capsule { radius, height } => {
|
||||
Vec3::new(*radius * 2.0, *height, *radius * 2.0)
|
||||
}
|
||||
ColliderShapeDesc::StaticMesh { .. } => Vec3::ONE,
|
||||
}
|
||||
.max(Vec3::splat(0.001));
|
||||
|
||||
match shape_kind {
|
||||
"Sphere" => ColliderShapeDesc::Sphere {
|
||||
radius: dimensions.max_element() * 0.5,
|
||||
},
|
||||
"Capsule" => ColliderShapeDesc::Capsule {
|
||||
radius: dimensions.x.max(dimensions.z) * 0.5,
|
||||
height: dimensions.y,
|
||||
},
|
||||
"Static Mesh" => ColliderShapeDesc::static_mesh(renderer_meshes),
|
||||
_ => ColliderShapeDesc::Cuboid {
|
||||
x_length: dimensions.x,
|
||||
y_length: dimensions.y,
|
||||
z_length: dimensions.z,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn dimension_drag(ui: &mut egui::Ui, label: &str, value: &mut f32) -> bool {
|
||||
property_row(ui, label, |ui| {
|
||||
ui.add_sized(
|
||||
[fit_width(ui, 72.0, 120.0), 20.0],
|
||||
egui::DragValue::new(value)
|
||||
.range(0.0..=10_000.0)
|
||||
.range(0.001..=10_000.0)
|
||||
.speed(0.05)
|
||||
.min_decimals(2)
|
||||
.max_decimals(3),
|
||||
@@ -4839,3 +4919,30 @@ fn option_string_ui(ui: &mut egui::Ui, label: &str, value: &mut Option<String>)
|
||||
};
|
||||
changed
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod collider_inspector_tests {
|
||||
use super::*;
|
||||
use crate::history::{apply_command_undo, EditorHistory};
|
||||
|
||||
#[test]
|
||||
fn shape_switch_preserves_dimensions_and_is_one_undoable_edit() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<EditorHistory>();
|
||||
let original = ColliderDesc::static_cuboid(Vec3::new(2.0, 4.0, 6.0));
|
||||
let entity = world.spawn((LevelObject, original.clone())).id();
|
||||
|
||||
let sphere = ColliderDesc {
|
||||
shape: convert_collider_shape(&original.shape, "Sphere", Vec::new()),
|
||||
..original.clone()
|
||||
};
|
||||
assert_eq!(sphere.shape, ColliderShapeDesc::Sphere { radius: 3.0 });
|
||||
|
||||
set_collider_with_history(&mut world, entity, sphere.clone());
|
||||
assert_eq!(world.resource::<EditorHistory>().undo_depth(), 1);
|
||||
assert_eq!(world.get::<ColliderDesc>(entity), Some(&sphere));
|
||||
|
||||
apply_command_undo(&mut world);
|
||||
assert_eq!(world.get::<ColliderDesc>(entity), Some(&original));
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ use crate::assets::{AssetSelection, AssetSubAssetKind, EditorAssets};
|
||||
use crate::camera::EditorCamera;
|
||||
use crate::gizmos::{EditorGizmoMode, EditorGizmoSpace};
|
||||
use crate::render_target::ViewportRenderTarget;
|
||||
use crate::selection::{ViewportClick, ViewportPickStack};
|
||||
use crate::selection::{SelectedEntity, ViewportClick, ViewportPickStack};
|
||||
use crate::state::PlayPossession;
|
||||
use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
@@ -200,16 +200,54 @@ fn scene_view_render_badge(world: &World, ctx: &egui::Context, scene_rect: egui:
|
||||
});
|
||||
|
||||
if mode == EditorViewportMode::Collider {
|
||||
let health =
|
||||
world.get_resource::<crate::viewport::collider_diagnostics::ColliderDiagnosticsState>();
|
||||
let selected_entry = world
|
||||
.get_resource::<SelectedEntity>()
|
||||
.and_then(|selected| selected.0)
|
||||
.and_then(|entity| health.and_then(|health| health.entry(entity)));
|
||||
egui::Area::new(egui::Id::new("scene_view_collider_warning"))
|
||||
.fixed_pos(scene_rect.left_bottom() + egui::vec2(8.0, -28.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Collider view / meshes hidden")
|
||||
.color(WARNING)
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Collider View")
|
||||
.color(WARNING)
|
||||
.strong()
|
||||
.small(),
|
||||
);
|
||||
if let Some(health) = health {
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} ready {} disabled {} warning {} invalid",
|
||||
health.valid_actors,
|
||||
health.disabled_actors,
|
||||
health.warning_actors,
|
||||
health.error_actors
|
||||
))
|
||||
.color(TEXT_MUTED)
|
||||
.small(),
|
||||
);
|
||||
}
|
||||
});
|
||||
if let Some(entry) = selected_entry {
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} / {} / {}",
|
||||
entry.actor_name,
|
||||
entry.shape_label,
|
||||
if entry.runtime_ready {
|
||||
"hydrated"
|
||||
} else {
|
||||
"not hydrated"
|
||||
}
|
||||
))
|
||||
.color(SELECTION)
|
||||
.small(),
|
||||
);
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user