add overlapBox/Sphere/Capsule function, fixed OnWake/OnSleep not work
This commit is contained in:
@ -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()
|
||||
|
||||
@ -143,8 +143,9 @@ namespace Prism
|
||||
};
|
||||
SceneType m_SceneType;
|
||||
|
||||
bool m_ViewportPanelMouseOver = false;
|
||||
bool m_ViewportPanelHovered = false;
|
||||
bool m_ViewportPanelFocused = false;
|
||||
bool m_ShowPhysicsSettings = false;
|
||||
|
||||
enum class SceneState
|
||||
{
|
||||
|
||||
@ -2,15 +2,15 @@ Scene: Scene Name
|
||||
Environment:
|
||||
AssetPath: assets/env/pink_sunrise_4k.hdr
|
||||
Light:
|
||||
Direction: [-0.787, -0.73299998, 1]
|
||||
Direction: [-0.787, -0.733, 1]
|
||||
Radiance: [1, 1, 1]
|
||||
Multiplier: 0.514999986
|
||||
Multiplier: 0.515
|
||||
Entities:
|
||||
- Entity: 3247025703490125974
|
||||
TagComponent:
|
||||
Tag: Player
|
||||
TransformComponent:
|
||||
Position: [2.80803752, 1.5, 0]
|
||||
Position: [2.8080375, 1.5, 0]
|
||||
Rotation: [1, 0, 0, 0]
|
||||
Scale: [2, 2, 2]
|
||||
ScriptComponent:
|
||||
@ -25,23 +25,30 @@ Entities:
|
||||
- Name: JumpForce
|
||||
Type: 1
|
||||
Data: 50
|
||||
- Name: MouseSensitivity
|
||||
Type: 1
|
||||
Data: 10
|
||||
- Name: Distance
|
||||
Type: 1
|
||||
Data: 0
|
||||
MeshComponent:
|
||||
AssetPath: assets/meshes/Capsule.fbx
|
||||
RigidBodyComponent:
|
||||
BodyType: 1
|
||||
Mass: 1
|
||||
IsKinematic: false
|
||||
Layer: 1
|
||||
Constraints:
|
||||
LockPositionX: false
|
||||
LockPositionY: false
|
||||
LockPositionZ: false
|
||||
LockRotationX: true
|
||||
LockRotationY: false
|
||||
LockRotationY: true
|
||||
LockRotationZ: true
|
||||
PhysicsMaterialComponent:
|
||||
StaticFriction: 0.100000001
|
||||
DynamicFriction: 0.100000001
|
||||
Bounciness: 0.100000001
|
||||
StaticFriction: 0.1
|
||||
DynamicFriction: 0.1
|
||||
Bounciness: 0.1
|
||||
MeshColliderComponent:
|
||||
AssetPath: assets/meshes/Capsule.fbx
|
||||
IsTrigger: false
|
||||
@ -49,15 +56,16 @@ Entities:
|
||||
TagComponent:
|
||||
Tag: Mesh Collider
|
||||
TransformComponent:
|
||||
Position: [-2.60455179, 1, -0.00171399117]
|
||||
Position: [-2.6045518, 1, -0.0017139912]
|
||||
Rotation: [1, 0, 0, 0]
|
||||
Scale: [1, 1, 1]
|
||||
MeshComponent:
|
||||
AssetPath: assets/meshes/Sphere1m.fbx
|
||||
RigidBodyComponent:
|
||||
BodyType: 1
|
||||
Mass: 0.100000001
|
||||
Mass: 0.1
|
||||
IsKinematic: false
|
||||
Layer: 1
|
||||
Constraints:
|
||||
LockPositionX: false
|
||||
LockPositionY: false
|
||||
@ -68,7 +76,7 @@ Entities:
|
||||
PhysicsMaterialComponent:
|
||||
StaticFriction: 1
|
||||
DynamicFriction: 1
|
||||
Bounciness: 0.100000001
|
||||
Bounciness: 0.1
|
||||
MeshColliderComponent:
|
||||
AssetPath: assets/meshes/Sphere1m.fbx
|
||||
IsTrigger: false
|
||||
@ -85,6 +93,7 @@ Entities:
|
||||
BodyType: 1
|
||||
Mass: 0.5
|
||||
IsKinematic: false
|
||||
Layer: 0
|
||||
Constraints:
|
||||
LockPositionX: false
|
||||
LockPositionY: false
|
||||
@ -104,7 +113,7 @@ Entities:
|
||||
TagComponent:
|
||||
Tag: Sphere
|
||||
TransformComponent:
|
||||
Position: [-3.98769951, 1, -1.96695328e-06]
|
||||
Position: [-3.9876995, 1, -1.9669533e-06]
|
||||
Rotation: [1, 0, 0, 0]
|
||||
Scale: [1, 1, 1]
|
||||
MeshComponent:
|
||||
@ -113,17 +122,18 @@ Entities:
|
||||
BodyType: 1
|
||||
Mass: 1
|
||||
IsKinematic: false
|
||||
Layer: 1
|
||||
Constraints:
|
||||
LockPositionX: false
|
||||
LockPositionY: false
|
||||
LockPositionZ: false
|
||||
LockRotationX: true
|
||||
LockRotationY: true
|
||||
LockRotationZ: true
|
||||
LockRotationX: false
|
||||
LockRotationY: false
|
||||
LockRotationZ: false
|
||||
PhysicsMaterialComponent:
|
||||
StaticFriction: 0.100000001
|
||||
DynamicFriction: 0.100000001
|
||||
Bounciness: 0.100000001
|
||||
StaticFriction: 0.1
|
||||
DynamicFriction: 0.1
|
||||
Bounciness: 0.1
|
||||
SphereColliderComponent:
|
||||
Radius: 0.5
|
||||
IsTrigger: false
|
||||
@ -131,7 +141,7 @@ Entities:
|
||||
TagComponent:
|
||||
Tag: Camera
|
||||
TransformComponent:
|
||||
Position: [2.80800009, 2.25, 0]
|
||||
Position: [2.808, 2.25, 0]
|
||||
Rotation: [1, 0, 0, 0]
|
||||
Scale: [1, 1, 1]
|
||||
CameraComponent:
|
||||
@ -150,6 +160,7 @@ Entities:
|
||||
BodyType: 0
|
||||
Mass: 1
|
||||
IsKinematic: false
|
||||
Layer: 0
|
||||
Constraints:
|
||||
LockPositionX: false
|
||||
LockPositionY: false
|
||||
@ -165,3 +176,7 @@ Entities:
|
||||
Offset: [0, 0, 0]
|
||||
Size: [1, 1, 1]
|
||||
IsTrigger: false
|
||||
PhysicsLayers:
|
||||
- Name: Default
|
||||
CollidesWith:
|
||||
[]
|
||||
Reference in New Issue
Block a user