- App/editor: Hierarchy/Inspector/Viewport/Stats 四面板 + DockBuilder 默认布局,main.cpp 瘦身为场景搭建与生命周期 - 显示链: Tonemap→PresentTarget 经 ImGui::Image 呈现(零色偏),backbuffer 仅承载 ImGui;Direct/Viewport 双显示模式 + 面板分辨率上报 - 帧首同步 BeginFrameSync: resize/vsync/尺寸/模式意图统一帧首落定(修描述符悬垂);修复 vsync 意图未落 swapchain 导致的每帧重建交换链 - 输入: Editor 每帧判定键盘/鼠标归属(打字让位、Viewport hover/focus 放行、Fullscreen 全放行) - 材质: roughness 独立槽位 + 非 glTF 金属/粗糙贴图映射;透明队列 depthWrite=FALSE + translucent 独立 shader + scratch 清帧 - FBX: 非蒙皮网格烘焙节点链全局变换(Z-up 旋转/单位换算落顶点) - Hierarchy 行 ImGui ID 以 UUID 作用域(重名不冲突、改名不丢选中)
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
//
|
|
// HierarchyPanel.cpp:实体列表实现。
|
|
//
|
|
|
|
#include "HierarchyPanel.h"
|
|
#include "Engine/ECS/Components.h"
|
|
#include "Engine/ECS/EntityHandle.h" // CreateEntity 返回完整 EntityHandle
|
|
|
|
#include <imgui.h>
|
|
|
|
using namespace Engine;
|
|
|
|
namespace {
|
|
struct ScopedID {
|
|
explicit ScopedID(const u64 uuid) {
|
|
ImGui::PushID(reinterpret_cast<const void*>(uuid));
|
|
}
|
|
~ScopedID() {ImGui::PopID(); }
|
|
};
|
|
}
|
|
|
|
void HierarchyPanel::Draw(const EditorContext& ctx, entt::entity& selected)
|
|
{
|
|
ImGui::Begin("Hierarchy");
|
|
|
|
// 工具栏:创建实体(在遍历之前,不修改遍历中的注册表结构)
|
|
if (ImGui::Button("+ Create Entity"))
|
|
{
|
|
const auto e = ctx.scene->CreateEntity("Entity");
|
|
selected = e;
|
|
}
|
|
ImGui::Separator();
|
|
|
|
auto& reg = ctx.scene->GetRegistry();
|
|
|
|
reg.view<Engine::ECS::NameComponent>().each(
|
|
[&](const entt::entity e, const Engine::ECS::NameComponent& name)
|
|
{
|
|
const bool isSelected = (selected == e);
|
|
|
|
u64 rowId = static_cast < uint64_t >( static_cast < uint32_t >(e));
|
|
if (const auto * id = reg.try_get<Engine::ECS::IdComponent>(e)) {
|
|
rowId = id->uuid.Value();
|
|
}
|
|
const ScopedID scope (rowId);
|
|
|
|
const std::string label = name.name.empty() ? "(unnamed)" : name.name;
|
|
if (ImGui::Selectable(label.c_str(), isSelected))
|
|
{
|
|
selected = e;
|
|
}
|
|
|
|
// 右键菜单:删除(延迟销毁,帧尾统一 flush)
|
|
if (ImGui::BeginPopupContextItem("entity_ctx"))
|
|
{
|
|
if (ImGui::MenuItem("Delete"))
|
|
{
|
|
ctx.scene->DestroyEntity(e);
|
|
if (selected == e)
|
|
{
|
|
selected = entt::null;
|
|
}
|
|
}
|
|
ImGui::EndPopup();
|
|
}
|
|
|
|
// 组件徽标 + 悬停清单
|
|
std::string badge;
|
|
if (reg.all_of<Engine::ECS::MeshRendererComponent>(e)) badge += "[M]";
|
|
if (reg.all_of<Engine::ECS::AnimationComponent>(e)) badge += "[A]";
|
|
if (reg.all_of<Engine::ECS::CameraComponent>(e)) badge += "[C]";
|
|
if (reg.all_of<Engine::ECS::LightComponent>(e)) badge += "[L]";
|
|
if (!badge.empty())
|
|
{
|
|
ImGui::SameLine();
|
|
ImGui::TextDisabled("%s", badge.c_str());
|
|
if (ImGui::IsItemHovered())
|
|
{
|
|
ImGui::SetTooltip(
|
|
"M=Mesh A=Animation C=Camera L=Light");
|
|
}
|
|
}
|
|
});
|
|
|
|
ImGui::End();
|
|
}
|