picking + entity names

This commit is contained in:
Jonas H
2026-03-05 15:05:19 +01:00
parent 5e5c6a47e7
commit bab54b6f21
9 changed files with 400 additions and 50 deletions

View File

@@ -1,7 +1,11 @@
use dear_imgui_rs::{Condition, Context};
use dear_imgui_wgpu::{WgpuInitInfo, WgpuRenderer};
use glam::EulerRot;
use sdl3_sys::events::SDL_Event;
use crate::entity::EntityHandle;
use crate::world::World;
pub struct FrameStats
{
pub fps: f32,
@@ -57,7 +61,12 @@ impl Inspector
self.imgui.io().want_capture_mouse()
}
pub fn build_ui(&mut self, stats: &FrameStats)
pub fn build_ui(
&mut self,
stats: &FrameStats,
world: &World,
selected_entity: Option<EntityHandle>,
)
{
let ui = self.imgui.frame();
ui.window("Inspector")
@@ -68,6 +77,113 @@ impl Inspector
ui.text(format!("Physics: {:.1} ms", stats.physics_budget_ms));
ui.text(format!("Draw calls: {}", stats.draw_call_count));
});
if let Some(entity) = selected_entity
{
ui.window("Entity")
.position([10.0, 120.0], Condition::FirstUseEver)
.build(|| {
let name = world
.names
.get(entity)
.cloned()
.unwrap_or_else(|| format!("Entity #{}", entity));
ui.text(format!("Name: {}", name));
ui.text(format!("ID: {}", entity));
ui.separator();
ui.text("Transform");
if let Some(transform) = world.transforms.get(entity)
{
let p = transform.position;
ui.text(format!(" Pos ({:.2}, {:.2}, {:.2})", p.x, p.y, p.z));
let (ex, ey, ez) = transform.rotation.to_euler(EulerRot::XYZ);
ui.text(format!(
" Rot ({:.1}, {:.1}, {:.1}) deg",
ex.to_degrees(),
ey.to_degrees(),
ez.to_degrees()
));
let s = transform.scale;
ui.text(format!(" Scale ({:.2}, {:.2}, {:.2})", s.x, s.y, s.z));
}
else
{
ui.text(" (no transform)");
}
ui.separator();
ui.text("Components");
if world.meshes.get(entity).is_some()
{
ui.text(" Mesh");
}
if world.physics.get(entity).is_some()
{
ui.text(" Physics");
}
if let Some(m) = world.movements.get(entity)
{
ui.text(format!(
" Movement (max_speed {:.1})",
m.max_walking_speed
));
}
if world.jumps.get(entity).is_some()
{
ui.text(" Jump");
}
if world.inputs.get(entity).is_some()
{
ui.text(" Input");
}
if world.player_tags.get(entity).is_some()
{
ui.text(" [Player]");
}
if world.tree_tags.get(entity).is_some()
{
ui.text(" [Tree]");
}
if let Some(cam) = world.cameras.get(entity)
{
ui.text(format!(
" Camera fov={:.0} near={:.2} far={:.0}",
cam.fov.to_degrees(),
cam.near,
cam.far
));
}
if let Some(spot) = world.spotlights.get(entity)
{
let o = spot.offset;
ui.text(format!(
" Spotlight offset ({:.1}, {:.1}, {:.1})",
o.x, o.y, o.z
));
}
if let Some(ti) = world.tree_instances.get(entity)
{
ui.text(format!(" TreeInstances ({})", ti.instances.len()));
}
if world.follows.get(entity).is_some()
{
ui.text(" Follow");
}
if world.rotates.get(entity).is_some()
{
ui.text(" Rotate");
}
if let Some(d) = world.dissolves.get(entity)
{
ui.text(format!(" Dissolve ({:.2})", d.amount));
}
});
}
}
pub fn render(&mut self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView)

View File

@@ -78,5 +78,6 @@ pub fn editor_loop(
{
camera_noclip_system(world, input_state, delta);
}
editor.inspector.build_ui(stats);
let selected = editor.selected_entity;
editor.inspector.build_ui(stats, world, selected);
}