add overlapBox/Sphere/Capsule function, fixed OnWake/OnSleep not work

This commit is contained in:
2025-12-28 22:40:48 +08:00
parent d0eed3a33d
commit 9a44dd8d79
34 changed files with 1439 additions and 280 deletions

View File

@ -9,6 +9,7 @@
#include "glm/gtx/matrix_decompose.hpp"
#include "Prism/Core/Input.h"
#include "Prism/Editor/PhysicsSettingsWindow.h"
#include "Prism/Physics/Physics3D.h"
#include "Prism/Renderer/Renderer2D.h"
#include "Prism/Script/ScriptEngine.h"
@ -192,7 +193,7 @@ namespace Prism
{
case SceneState::Edit:
{
// if (m_ViewportPanelFocused)
if (m_ViewportPanelHovered || m_ViewportPanelFocused)
m_EditorCamera.OnUpdate(deltaTime);
m_EditorScene->OnRenderEditor(deltaTime, m_EditorCamera);
@ -361,6 +362,13 @@ namespace Prism
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit"))
{
ImGui::MenuItem("Physics Settings", nullptr, &m_ShowPhysicsSettings);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools"))
{
// PhysX Debugger
@ -380,6 +388,7 @@ namespace Prism
}
m_SceneHierarchyPanel->OnImGuiRender();
PhysicsSettingsWindow::OnImGuiRender(&m_ShowPhysicsSettings);
ImGui::Begin("Materials");
@ -682,9 +691,13 @@ namespace Prism
{
if (ImGui::TreeNode(shader->GetName().c_str()))
{
std::string buttonName = "Reload##" + shader->GetName();
if (ImGui::Button(buttonName.c_str()))
const std::string buttonName = shader->GetName();
if (ImGui::Button(("Reload##" + buttonName).c_str()))
{
PM_CLIENT_INFO("Reloading Shader: {0}", buttonName);
shader->Reload();
}
ImGui::TreePop();
}
}
@ -735,7 +748,7 @@ namespace Prism
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::Begin("Viewport");
m_ViewportPanelMouseOver = ImGui::IsWindowHovered();
m_ViewportPanelHovered = ImGui::IsWindowHovered();
m_ViewportPanelFocused = ImGui::IsWindowFocused();
auto viewportOffset = ImGui::GetCursorPos(); // includes tab bar
@ -809,7 +822,7 @@ namespace Prism
{
if (m_SceneState == SceneState::Edit)
{
if (m_ViewportPanelMouseOver)
if (m_ViewportPanelHovered)
m_EditorCamera.OnEvent(e);
m_EditorScene->OnEvent(e);
@ -857,42 +870,49 @@ namespace Prism
if (Input::IsKeyPressed(KeyCode::LEFT_CONTROL))
{
switch (e.GetKeyCode())
const bool IsShiftPressed = Input::IsKeyPressed(KeyCode::LEFT_SHIFT);
if (!IsShiftPressed)
{
case KeyCode::O:
OpenScene();
break;
case KeyCode::S:
SaveScene();
break;
case KeyCode::B:
// Toggle bounding boxes
m_UIShowBoundingBoxes = !m_UIShowBoundingBoxes;
ShowBoundingBoxes(m_UIShowBoundingBoxes, m_UIShowBoundingBoxesOnTop);
break;
case KeyCode::D:
if (m_SelectionContext.size())
switch (e.GetKeyCode())
{
Entity selectedEntity = m_SelectionContext[0].Entity;
m_EditorScene->DuplicateEntity(selectedEntity);
case KeyCode::O:
OpenScene();
break;
case KeyCode::S:
SaveScene();
break;
case KeyCode::B:
// Toggle bounding boxes
m_UIShowBoundingBoxes = !m_UIShowBoundingBoxes;
ShowBoundingBoxes(m_UIShowBoundingBoxes, m_UIShowBoundingBoxesOnTop);
break;
case KeyCode::D:
if (m_SelectionContext.size())
{
const Entity selectedEntity = m_SelectionContext[0].Entity;
m_EditorScene->DuplicateEntity(selectedEntity);
}
break;
case KeyCode::G:
// Toggle grid
SceneRenderer::GetOptions().ShowGrid = !SceneRenderer::GetOptions().ShowGrid;
break;
}
break;
case KeyCode::G:
// Toggle grid
SceneRenderer::GetOptions().ShowGrid = !SceneRenderer::GetOptions().ShowGrid;
break;
}
if (Input::IsKeyPressed(PM_KEY_LEFT_SHIFT))
{
if (IsShiftPressed) {
switch (e.GetKeyCode())
{
case KeyCode::S:
SaveSceneAs();
break;
default:
break;
}
}
// TODO: ALT TAB
}
return false;
@ -902,7 +922,7 @@ namespace Prism
{
auto [mx, my] = Input::GetMousePosition();
if (e.GetMouseButton() == PM_MOUSE_BUTTON_LEFT && !Input::IsKeyPressed(KeyCode::LEFT_ALT) && !ImGuizmo::IsOver() && m_SceneState != SceneState::Play)
if (m_ViewportPanelHovered && e.GetMouseButton() == PM_MOUSE_BUTTON_LEFT && !Input::IsKeyPressed(KeyCode::LEFT_ALT) && !ImGuizmo::IsOver() && m_SceneState != SceneState::Play)
{
auto [mouseX, mouseY] = GetMouseViewportSpace();
if (mouseX > -1.0f && mouseX < 1.0f && mouseY > -1.0f && mouseY < 1.0f)
@ -912,9 +932,9 @@ namespace Prism
m_SelectionContext.clear();
m_EditorScene->SetSelectedEntity({});
const auto meshEntities = m_EditorScene->GetAllEntitiesWith<MeshComponent>();
for (auto e : meshEntities)
for (const auto aEntity : meshEntities)
{
Entity entity = { e, m_EditorScene.Raw() };
Entity entity = { aEntity, m_EditorScene.Raw() };
auto mesh = entity.GetComponent<MeshComponent>().Mesh;
if (!mesh)
@ -970,9 +990,7 @@ namespace Prism
SelectedSubmesh selection;
if (entity.HasComponent<MeshComponent>())
{
auto& meshComp = entity.GetComponent<MeshComponent>();
if (meshComp.Mesh)
if (auto& meshComp = entity.GetComponent<MeshComponent>(); meshComp.Mesh)
{
selection.Mesh = &meshComp.Mesh->GetSubmeshes()[0];
}
@ -1066,6 +1084,7 @@ namespace Prism
void EditorLayer::SaveScene()
{
PM_CLIENT_INFO("Saving scene to: {0}", m_SceneFilePath);
SceneSerializer serializer(m_EditorScene);
serializer.Serialize(m_SceneFilePath);
}
@ -1076,6 +1095,7 @@ namespace Prism
std::string filepath = app.SaveFile("Prism Scene (*.hsc)\0*.hsc\0");
if (!filepath.empty())
{
PM_CLIENT_INFO("Saving scene to: {0}", m_SceneFilePath);
SceneSerializer serializer(m_EditorScene);
serializer.Serialize(filepath);
@ -1112,6 +1132,8 @@ namespace Prism
m_SelectionContext.clear();
ScriptEngine::SetSceneContext(m_EditorScene);
m_SceneHierarchyPanel->SetContext(m_EditorScene);
Input::SetCursorMode(CursorMode::Normal);
}
float EditorLayer::GetSnapValue()