- ImGuizmo 接入:Lib/ImGuizmo(src/ 布局)静态库,IMGUI_DEFINE_MATH_OPERATORS - ViewportPanel:Vulkan→GL 投影转换(Y 翻回 + 深度 [-1,1])、 SetDrawlist/SetRect 叠加绘制、decompose 写回 TransformComponent - W/E/R 切换(UE 语义);拖拽中 BlockingMouse 门控(输入归 Gizmo) - Dynamic 刚体选中提示:物理每帧写回,编辑被覆盖 - 修复:GizmoState.op 初值 0 无轴位(ImGuizmo::TRANSLATE=7)导致杆不绘制 - 点击拾取门控:抓杆时(IsOver/IsUsing)不发 pick 请求
57 lines
2.3 KiB
C++
57 lines
2.3 KiB
C++
//
|
||
// ViewportPanel:场景渲染输出面板。
|
||
//
|
||
// tonemap 输出经 ImGui::Image 显示(Editor 模式),并提供
|
||
// Editor Viewport / Fullscreen 显示模式切换。面板可用区域
|
||
// (物理像素)上报为渲染分辨率 → 画面精确填满面板。
|
||
//
|
||
// 点击拾取(UE 式 GPU HitProxy):单击 → NDC 请求 id 渲染;结果
|
||
// 由 Draw 每帧轮询取走(像素级,与视觉画面一致)。
|
||
//
|
||
|
||
#ifndef HELLOVULKAN_VIEWPORTPANEL_H
|
||
#define HELLOVULKAN_VIEWPORTPANEL_H
|
||
|
||
#include "EditorContext.h"
|
||
|
||
#include <imgui.h> // ImVec2(RequestPickAt 签名)
|
||
#include <entt/entt.hpp>
|
||
#include <optional>
|
||
|
||
// Viewport 面板每帧上报的输入焦点状态(Hazel 模式:编辑器据此决定
|
||
// 游戏侧输入是否放行——悬停/持焦 Viewport 才拥有 WASD/鼠标)
|
||
struct ViewportInputState {
|
||
bool hovered = false; // 鼠标悬停在 Viewport 面板上
|
||
bool focused = false; // Viewport 面板持有键盘焦点
|
||
};
|
||
|
||
// Gizmo 交互状态(Editor 持有、ViewportPanel 写):
|
||
// op 取 ImGuizmo::OPERATION 位掩码(TRANSLATE=7=三轴位或运算,非 0
|
||
// 起始枚举;0 = 无任何轴位 → Gizmo 完全不绘制),int 存储避免本
|
||
// 头文件 include ImGuizmo.h(拖入 imgui 宏依赖顺序)
|
||
// W/E/R 切换(UE 语义);dragging 拉起 Editor::BlockingMouse 门控
|
||
struct GizmoState {
|
||
int op = 7; // ImGuizmo::TRANSLATE(TRANSLATE_X|Y|Z)
|
||
bool dragging = false; // 拖拽中(IsUsing)→ 鼠标归 Gizmo 不给游戏侧
|
||
};
|
||
|
||
class ViewportPanel {
|
||
public:
|
||
// 返回值:本帧拾取命中的实体(无点击/未命中 = nullopt 或 null);
|
||
// Editor 据此 SelectEntity(面板不持有选中状态)
|
||
std::optional<entt::entity> Draw(const EditorContext& ctx,
|
||
ViewportInputState& out,
|
||
GizmoState& gizmo,
|
||
entt::entity selected) const;
|
||
|
||
private:
|
||
// Image 区域内的鼠标位置 → NDC → Renderer::RequestPick
|
||
//(结果下一帧由 Draw 轮询 TakePickResult 取走)
|
||
void RequestPickAt(const EditorContext& ctx, const ImVec2& size) const;
|
||
|
||
// 命中打印:实体名 + collider 参数对照(诊断物理盒 ≠ 视觉用)
|
||
static void LogPick(const EditorContext& ctx, entt::entity e);
|
||
};
|
||
|
||
#endif //HELLOVULKAN_VIEWPORTPANEL_H
|