Fix selection outline never showing for the first entity

entt entity 0's integral bits are 0, colliding with the "no selection"
sentinel: u32 selected == 0 meant "clear selection", so the scene's
first-created entity could never be outlined. Replaced with
std::optional<u32> + FrameSceneData::selectedEntityValid.

Also restore per-batch instance contiguity broken by the batchMats
flattening (e038cb3): entities sharing a mesh scatter across the flat
instance array in collection order. ViewScratch now tracks per-batch
singly-linked lists and appendView aggregates each batch into a
contiguous range, preserving the flat-array performance intent.

Hierarchy click selection now routes through SelectEntity so outline
stays in sync when picking from the panel.
This commit is contained in:
2026-10-05 00:39:48 +08:00
parent e038cb39fa
commit dec171cd1e
8 changed files with 97 additions and 40 deletions
+10 -1
View File
@@ -131,7 +131,16 @@ void Editor::Draw()
ImGui::End();
// 常规面板窗口(窗口名 = docking 身份)
if (m_ShowHierarchy) m_Hierarchy->Draw(m_Ctx, m_Selected);
if (m_ShowHierarchy)
{
const entt::entity prev = m_Selected;
m_Hierarchy->Draw(m_Ctx, m_Selected);
// 树点选同步描边(面板直写 m_Selected,不走 Viewport 的
// SelectEntity 返回值通道;对比前后变化触发)
if (m_Selected != prev) {
SelectEntity(m_Selected);
}
}
if (m_ShowInspector) m_Inspector->Draw(m_Ctx, m_Selected);
if (m_ShowViewport)
{
+7 -4
View File
@@ -21,6 +21,7 @@
#include <entt/entt.hpp>
#include <memory>
#include <optional>
class HierarchyPanel;
class InspectorPanel;
@@ -67,16 +68,18 @@ private:
void DoStop(); // TogglePlay 的 Stop 半程(恢复 + 回编辑器 + 冻结)
// ---- 选中状态 ----
// 同步描边:Renderer 落帧后 SelectionMask/Outline 只画选中实体
//(bits = 实体位模式,0 = 清选中)
// 同步描边:Renderer 落帧后 SelectionMask/Outline 只画选中实体。
// nullopt = 清选中——实体 0 号(场景首个创建)位模式 = 0,
// 不能拿位值兼作哨兵("第一个模型无描边"的根因)
void SelectEntity(entt::entity e)
{
m_Selected = e;
if (m_Ctx.renderer) {
m_Ctx.renderer->SetSelectedEntity(
e == entt::null
? 0u
: static_cast<Engine::u32>(entt::to_integral(e)));
? std::optional<Engine::u32>{}
: std::optional<Engine::u32>(
static_cast<Engine::u32>(entt::to_integral(e))));
}
}
entt::entity GetSelected() const { return m_Selected; }