mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-03 14:09:46 +03:00
Better Gizmos
Gizmos now display half opacity when occluded, same for lines Improved editor camera, should keep updating even if not controlled Viewport should not grab input when another imgui element is over it
This commit is contained in:
@@ -24,19 +24,19 @@
|
||||
#include <src/Scene/Components/AudioEmitterComponent.h>
|
||||
|
||||
|
||||
GizmoDrawer::GizmoDrawer()
|
||||
GizmoDrawer::GizmoDrawer(EditorInterface* editor)
|
||||
{
|
||||
mLineShader = Nuake::ShaderManager::GetShader("Resources/Shaders/line.shader");
|
||||
m_LineShader = Nuake::ShaderManager::GetShader("Resources/Shaders/line.shader");
|
||||
|
||||
mAxisLineBuffer = CreateRef<Nuake::VertexArray>();
|
||||
mAxisLineBuffer->Bind();
|
||||
m_AxisLineBuffer = CreateRef<Nuake::VertexArray>();
|
||||
m_AxisLineBuffer->Bind();
|
||||
|
||||
mAxisLineVertexBuffer = CreateRef<VertexBuffer>(vertices.data(), vertices.size() * sizeof(Nuake::LineVertex));
|
||||
m_AxisLineVertexBuffer = CreateRef<VertexBuffer>(m_Vertices.data(), m_Vertices.size() * sizeof(Nuake::LineVertex));
|
||||
auto vblayout = CreateRef<VertexBufferLayout>();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
mAxisLineBuffer->AddBuffer(*mAxisLineVertexBuffer, *vblayout);
|
||||
m_AxisLineBuffer->AddBuffer(*m_AxisLineVertexBuffer, *vblayout);
|
||||
|
||||
GenerateSphereGizmo();
|
||||
|
||||
@@ -72,19 +72,21 @@ GizmoDrawer::GizmoDrawer()
|
||||
LineVertex{Vector3(1.0f, 1.0f, 1.f), cubeColor}
|
||||
};
|
||||
|
||||
mBoxBuffer = CreateRef<Nuake::VertexArray>();
|
||||
mBoxBuffer->Bind();
|
||||
m_BoxBuffer = CreateRef<Nuake::VertexArray>();
|
||||
m_BoxBuffer->Bind();
|
||||
|
||||
mBoxVertexBuffer = CreateRef<VertexBuffer>(mBoxVertices.data(), mBoxVertices.size() * sizeof(Nuake::LineVertex));
|
||||
m_BoxVertexBuffer = CreateRef<VertexBuffer>(mBoxVertices.data(), mBoxVertices.size() * sizeof(Nuake::LineVertex));
|
||||
|
||||
mBoxBuffer->AddBuffer(*mBoxVertexBuffer, *vblayout);
|
||||
m_BoxBuffer->AddBuffer(*m_BoxVertexBuffer, *vblayout);
|
||||
|
||||
// Load gizmos
|
||||
ModelLoader loader;
|
||||
_gizmos = std::map<std::string, Ref<Model>>();
|
||||
m_Gizmos = std::map<std::string, Ref<Model>>();
|
||||
//_gizmos["cam"] = loader.LoadModel("Resources/Models/Camera.gltf");
|
||||
//_gizmos["light"] = loader.LoadModel("Resources/Models/Light.gltf");
|
||||
//_gizmos["player"] = loader.LoadModel("Resources/Models/Camera.gltf");
|
||||
|
||||
m_Editor = editor;
|
||||
}
|
||||
|
||||
void GizmoDrawer::GenerateSphereGizmo()
|
||||
@@ -116,19 +118,48 @@ void GizmoDrawer::GenerateSphereGizmo()
|
||||
vert2 = Vector3(x2, 0, z2);
|
||||
}
|
||||
|
||||
circleVertices.push_back(LineVertex{ vert1, Color(1.0, 0, 0.0, 0.5) });
|
||||
circleVertices.push_back(LineVertex{ vert2, Color(1.0, 0, 0.0, 0.5) });
|
||||
m_CircleVertices.push_back(LineVertex{ vert1, Color(1.0, 0, 0.0, 0.5) });
|
||||
m_CircleVertices.push_back(LineVertex{ vert2, Color(1.0, 0, 0.0, 0.5) });
|
||||
}
|
||||
|
||||
mCircleBuffer = CreateRef<Nuake::VertexArray>();
|
||||
mCircleBuffer->Bind();
|
||||
m_CircleBuffer = CreateRef<Nuake::VertexArray>();
|
||||
m_CircleBuffer->Bind();
|
||||
|
||||
mCircleVertexBuffer = CreateRef<VertexBuffer>(circleVertices.data(), circleVertices.size() * sizeof(Nuake::LineVertex));
|
||||
m_CircleVertexBuffer = CreateRef<VertexBuffer>(m_CircleVertices.data(), m_CircleVertices.size() * sizeof(Nuake::LineVertex));
|
||||
auto vblayout = CreateRef<VertexBufferLayout>();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
mCircleBuffer->AddBuffer(*mCircleVertexBuffer, *vblayout);
|
||||
m_CircleBuffer->AddBuffer(*m_CircleVertexBuffer, *vblayout);
|
||||
}
|
||||
|
||||
bool GizmoDrawer::IsEntityInSelection(Nuake::Entity entity)
|
||||
{
|
||||
if (m_Editor->Selection.Type != EditorSelectionType::Entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using namespace Nuake;
|
||||
const Nuake::Entity selectedEntity = m_Editor->Selection.Entity;
|
||||
|
||||
if (selectedEntity.GetID() == entity.GetID())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
auto& parentComponent = entity.GetComponent<ParentComponent>();
|
||||
if (!parentComponent.HasParent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsEntityInSelection(parentComponent.Parent))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
@@ -140,46 +171,61 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
//glDepthFunc(GL_ALWAYS); // Disable built-in depth testing
|
||||
//glDepthMask(false); // Disable writing to the depth buffer
|
||||
{
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform());
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
mLineShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f);
|
||||
mAxisLineBuffer->Bind();
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform());
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f);
|
||||
m_AxisLineBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 6);
|
||||
}
|
||||
|
||||
glLineWidth(1.0f);
|
||||
glLineWidth(2.0f);
|
||||
auto boxColliderView = scene->m_Registry.view<TransformComponent, BoxColliderComponent>();
|
||||
for (auto e : boxColliderView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, box] = scene->m_Registry.get<TransformComponent, BoxColliderComponent>(e);
|
||||
|
||||
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
|
||||
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix, box.Size));
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix, box.Size));
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
mBoxBuffer->Bind();
|
||||
m_BoxBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 26);
|
||||
}
|
||||
|
||||
auto sphereColliderView = scene->m_Registry.view<TransformComponent, SphereColliderComponent>();
|
||||
for (auto e : sphereColliderView)
|
||||
{
|
||||
auto [transform, sphere] = scene->m_Registry.get<TransformComponent, SphereColliderComponent>(e);
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])), Vector3(sphere.Radius)));
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mCircleBuffer->Bind();
|
||||
auto [transform, sphere] = scene->m_Registry.get<TransformComponent, SphereColliderComponent>(e);
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])), Vector3(sphere.Radius)));
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
m_CircleBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 128);
|
||||
}
|
||||
|
||||
auto audioEmitterView = scene->m_Registry.view<TransformComponent, AudioEmitterComponent>();
|
||||
for (auto e : audioEmitterView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, emitter] = scene->m_Registry.get<TransformComponent, AudioEmitterComponent>(e);
|
||||
|
||||
// We dont need to draw the radius if its not spatialized
|
||||
@@ -189,80 +235,100 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
}
|
||||
|
||||
Vector3 globalPosition = Vector3(transform.GetGlobalTransform()[3]);
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), globalPosition), Vector3(emitter.MaxDistance)));
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), globalPosition), Vector3(emitter.MaxDistance)));
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
mCircleBuffer->Bind();
|
||||
m_CircleBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 128);
|
||||
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), globalPosition), Vector3(emitter.MinDistance)));
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), globalPosition), Vector3(emitter.MinDistance)));
|
||||
Nuake::RenderCommand::DrawLines(0, 128);
|
||||
}
|
||||
|
||||
auto capsuleColliderView = scene->m_Registry.view<TransformComponent, CapsuleColliderComponent>();
|
||||
for (auto e : capsuleColliderView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, capsule] = scene->m_Registry.get<TransformComponent, CapsuleColliderComponent>(e);
|
||||
|
||||
const auto entityId = (uint32_t)e;
|
||||
if (_CapsuleEntity.find(entityId) == _CapsuleEntity.end())
|
||||
if (m_CapsuleGizmo.find(entityId) == m_CapsuleGizmo.end())
|
||||
{
|
||||
_CapsuleEntity[entityId] = CreateScope<CapsuleGizmo>();
|
||||
m_CapsuleGizmo[entityId] = CreateScope<CapsuleGizmo>();
|
||||
}
|
||||
|
||||
_CapsuleEntity[entityId]->UpdateShape(capsule.Radius, capsule.Height);
|
||||
m_CapsuleGizmo[entityId]->UpdateShape(capsule.Radius, capsule.Height);
|
||||
|
||||
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
|
||||
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
_CapsuleEntity[entityId]->Bind();
|
||||
m_CapsuleGizmo[entityId]->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 264);
|
||||
}
|
||||
|
||||
auto cylinderColliderView = scene->m_Registry.view<TransformComponent, CylinderColliderComponent>();
|
||||
for (auto e : cylinderColliderView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, cylinder] = scene->m_Registry.get<TransformComponent, CylinderColliderComponent>(e);
|
||||
|
||||
const auto entityId = (uint32_t)e;
|
||||
if (_CylinderEntity.find(entityId) == _CylinderEntity.end())
|
||||
if (m_CylinderGizmo.find(entityId) == m_CylinderGizmo.end())
|
||||
{
|
||||
_CylinderEntity[entityId] = CreateScope<CylinderGizmo>();
|
||||
m_CylinderGizmo[entityId] = CreateScope<CylinderGizmo>();
|
||||
}
|
||||
|
||||
_CylinderEntity[entityId]->UpdateShape(cylinder.Radius, cylinder.Height);
|
||||
m_CylinderGizmo[entityId]->UpdateShape(cylinder.Radius, cylinder.Height);
|
||||
|
||||
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
|
||||
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
_CylinderEntity[entityId]->Bind();
|
||||
m_CylinderGizmo[entityId]->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 264);
|
||||
}
|
||||
|
||||
auto particleView = scene->m_Registry.view<TransformComponent, ParticleEmitterComponent>();
|
||||
for (auto e : particleView)
|
||||
{
|
||||
auto [transform, particle] = scene->m_Registry.get<TransformComponent, ParticleEmitterComponent>(e);
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])), Vector3(particle.Radius)));
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mCircleBuffer->Bind();
|
||||
auto [transform, particle] = scene->m_Registry.get<TransformComponent, ParticleEmitterComponent>(e);
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::scale(glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])), Vector3(particle.Radius)));
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
m_CircleBuffer->Bind();
|
||||
Nuake::RenderCommand::DrawLines(0, 128);
|
||||
}
|
||||
|
||||
auto meshColliderView = scene->m_Registry.view<TransformComponent, MeshColliderComponent, ModelComponent>();
|
||||
for (auto e : meshColliderView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, mesh, model] = scene->m_Registry.get<TransformComponent, MeshColliderComponent, ModelComponent>(e);
|
||||
|
||||
// Component has no mesh set.
|
||||
@@ -282,9 +348,9 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
|
||||
|
||||
mLineShader->Bind();
|
||||
mLineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
mLineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->Bind();
|
||||
m_LineShader->SetUniformMat4f("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix);
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
meshes[mesh.SubMesh]->Bind();
|
||||
@@ -317,6 +383,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
for (auto e : camView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/camera.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", (uint32_t)e + 1);
|
||||
auto [transform, camera] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
|
||||
|
||||
auto initialTransform = transform.GetGlobalTransform();
|
||||
@@ -330,14 +397,16 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
renderList.Flush(gizmoShader, true);
|
||||
|
||||
|
||||
// Lights
|
||||
auto lightView = scene->m_Registry.view<TransformComponent, LightComponent>();
|
||||
for (auto e : lightView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/light.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", (uint32_t)e + 1);
|
||||
auto [transform, light] = scene->m_Registry.get<TransformComponent, LightComponent>(e);
|
||||
|
||||
auto initialTransform = transform.GetGlobalTransform();
|
||||
@@ -351,15 +420,16 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
renderList.Flush(gizmoShader, true);
|
||||
|
||||
// Player
|
||||
auto characterControllerView = scene->m_Registry.view<TransformComponent, CharacterControllerComponent>();
|
||||
for (auto e : characterControllerView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/player.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", static_cast<uint32_t>(e) + 1);
|
||||
auto [transform, characterControllerComponent] = scene->m_Registry.get<TransformComponent, CharacterControllerComponent>(e);
|
||||
|
||||
auto initialTransform = transform.GetGlobalTransform();
|
||||
@@ -373,15 +443,17 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
renderList.Flush(gizmoShader, true);
|
||||
|
||||
|
||||
// Bones
|
||||
auto boneView = scene->m_Registry.view<TransformComponent, BoneComponent>();
|
||||
for (auto e : boneView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/bone.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", static_cast<uint32_t>(e) + 1);
|
||||
auto [transform, boneComponent] = scene->m_Registry.get<TransformComponent, BoneComponent>(e);
|
||||
|
||||
auto initialTransform = transform.GetGlobalTransform();
|
||||
@@ -394,14 +466,16 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.1, 0.1, 0.1));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
renderList.Flush(gizmoShader, true);
|
||||
|
||||
|
||||
auto audioView = scene->m_Registry.view<TransformComponent, AudioEmitterComponent>();
|
||||
for (auto e : audioView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/speaker.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", static_cast<uint32_t>(e) + 1);
|
||||
auto [transformComponent, audioEmitterComponent] = scene->m_Registry.get<TransformComponent, AudioEmitterComponent>(e);
|
||||
|
||||
auto initialTransform = transformComponent.GetGlobalTransform();
|
||||
@@ -414,9 +488,10 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
transform = glm::scale(transform, Vector3(0.5f, 0.5f, 0.5f));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, transform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
renderList.Flush(gizmoShader, true);
|
||||
|
||||
|
||||
// Revert to default depth testing
|
||||
//glDepthFunc(GL_LESS);
|
||||
|
||||
@@ -10,18 +10,22 @@
|
||||
|
||||
#include "Gizmos/CapsuleGizmo.h"
|
||||
#include "Gizmos/CylinderGizmo.h"
|
||||
#include "../Windows/EditorInterface.h"
|
||||
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
class GizmoDrawer
|
||||
{
|
||||
private:
|
||||
std::map<std::string, Ref<Model>> _gizmos;
|
||||
EditorInterface* m_Editor;
|
||||
Shader* m_LineShader;
|
||||
|
||||
std::map<uint32_t, Scope<CapsuleGizmo>> _CapsuleEntity;
|
||||
std::map<uint32_t, Scope<CylinderGizmo>> _CylinderEntity;
|
||||
std::map<std::string, Ref<Model>> m_Gizmos;
|
||||
std::map<uint32_t, Scope<CapsuleGizmo>> m_CapsuleGizmo;
|
||||
std::map<uint32_t, Scope<CylinderGizmo>> m_CylinderGizmo;
|
||||
|
||||
const std::vector<LineVertex> vertices
|
||||
const std::vector<LineVertex> m_Vertices
|
||||
{
|
||||
LineVertex {{10000.f, 0.0f, 0.0f}, {1.f, 0.f, 0.f, 1.f}},
|
||||
LineVertex {{0.0f, 0.0f, 0.0f }, {1.f, 0.f, 0.f, 1.f}},
|
||||
@@ -30,23 +34,28 @@ private:
|
||||
LineVertex {{0.f, 10000.f, 0.0f }, {0.f, 1.f, 0.f, 1.f}},
|
||||
LineVertex {{0.0f, 0.0f, 0.0f }, {0.f, 1.f, 0.f, 1.f}}
|
||||
};
|
||||
std::vector<LineVertex> circleVertices;
|
||||
Ref<VertexArray> mCircleBuffer;
|
||||
Ref<VertexBuffer> mCircleVertexBuffer;
|
||||
|
||||
std::vector<LineVertex> mBoxVertices;
|
||||
Ref<VertexArray> mBoxBuffer;
|
||||
Ref<VertexBuffer> mBoxVertexBuffer;
|
||||
std::vector<LineVertex> m_CircleVertices;
|
||||
Ref<VertexArray> m_CircleBuffer;
|
||||
Ref<VertexBuffer> m_CircleVertexBuffer;
|
||||
|
||||
Ref<VertexArray> mAxisLineBuffer;
|
||||
Ref<VertexBuffer> mAxisLineVertexBuffer;
|
||||
std::vector<LineVertex> m_BoxVertices;
|
||||
Ref<VertexArray> m_BoxBuffer;
|
||||
Ref<VertexBuffer> m_BoxVertexBuffer;
|
||||
|
||||
Ref<VertexArray> m_AxisLineBuffer;
|
||||
Ref<VertexBuffer> m_AxisLineVertexBuffer;
|
||||
|
||||
Shader* mLineShader;
|
||||
|
||||
void GenerateSphereGizmo();
|
||||
public:
|
||||
GizmoDrawer();
|
||||
GizmoDrawer(EditorInterface* editor);
|
||||
~GizmoDrawer() = default;
|
||||
|
||||
void DrawGizmos(Ref<Scene> scene, bool occluded);
|
||||
|
||||
|
||||
private:
|
||||
void GenerateSphereGizmo();
|
||||
bool IsEntityInSelection(Nuake::Entity entity);
|
||||
|
||||
};
|
||||
@@ -260,14 +260,14 @@ namespace Nuake {
|
||||
}
|
||||
}
|
||||
|
||||
if (m_IsHoveringViewport && !m_IsViewportFocused && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2))
|
||||
if (ImGui::IsWindowHovered() && m_IsHoveringViewport && !m_IsViewportFocused && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2))
|
||||
{
|
||||
ImGui::FocusWindow(ImGui::GetCurrentWindow());
|
||||
}
|
||||
|
||||
m_IsViewportFocused = ImGui::IsWindowFocused();
|
||||
|
||||
if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing() && m_IsViewportFocused)
|
||||
if (ImGui::GetIO().WantCaptureMouse && m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing() && m_IsViewportFocused)
|
||||
{
|
||||
const auto windowPosNuake = Vector2(windowPos.x, windowPos.y);
|
||||
auto& gbuffer = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer();
|
||||
@@ -2106,10 +2106,9 @@ namespace Nuake {
|
||||
|
||||
auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera;
|
||||
|
||||
editorCam->Update(ts, m_IsHoveringViewport);
|
||||
editorCam->Update(ts, m_IsHoveringViewport && m_IsViewportFocused);
|
||||
|
||||
const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid();
|
||||
|
||||
if (editorCam->IsFlying() && entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F))
|
||||
{
|
||||
editorCam->IsMoving = true;
|
||||
|
||||
@@ -154,6 +154,13 @@ namespace Nuake
|
||||
|
||||
return Vector2(xpos, ypos);
|
||||
}
|
||||
|
||||
void Input::SetMousePosition(const Vector2& position)
|
||||
{
|
||||
auto window = Window::Get()->GetHandle();
|
||||
glfwSetCursorPos(window, position.x, position.y);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
bool Input::Init()
|
||||
|
||||
@@ -156,6 +156,7 @@ namespace Nuake
|
||||
static float GetMouseX();
|
||||
static float GetMouseY();
|
||||
static Vector2 GetMousePosition();
|
||||
static void SetMousePosition(const Vector2& position);
|
||||
|
||||
static bool Init();
|
||||
static void Update();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Nuake
|
||||
void SetSize(const Vector2& size) { m_Size = size; }
|
||||
void UpdateSize(Vector2 size);
|
||||
|
||||
|
||||
uint32_t GetRenderID() const { return m_FramebufferID; }
|
||||
int ReadPixel(uint32_t attachment, const Vector2 coords);
|
||||
void SetDrawBuffer(GLenum draw);
|
||||
void SetReadBuffer(GLenum read);
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace Nuake
|
||||
{
|
||||
const auto defaultResolution = Vector2(1920, 1080);
|
||||
mGBuffer = CreateScope<FrameBuffer>(false, defaultResolution);
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT);
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT); // Depth
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT0); // Albedo
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT1); //
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT1); // Normal
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RGBA), GL_COLOR_ATTACHMENT2); // Material + unlit
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RED_INTEGER, GL_R32I, GL_INT), GL_COLOR_ATTACHMENT3);
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RED_INTEGER, GL_R32I, GL_INT), GL_COLOR_ATTACHMENT3); // Entity ID
|
||||
mGBuffer->SetTexture(CreateRef<Texture>(defaultResolution, GL_RED, GL_R16F, GL_FLOAT), GL_COLOR_ATTACHMENT4); // Emissive
|
||||
|
||||
mShadingBuffer = CreateScope<FrameBuffer>(true, defaultResolution);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
||||
#include "src/Core/Logger.h"
|
||||
#include <src/Vendors/imgui/imgui.h>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -79,7 +80,8 @@ namespace Nuake
|
||||
mouseLastY = y;
|
||||
}
|
||||
|
||||
if (hover && Input::IsMouseButtonDown(1))
|
||||
|
||||
if (controlled && Input::IsMouseButtonDown(1))
|
||||
{
|
||||
// Should probably not have speed binding in here.
|
||||
if (Input::YScroll != 0)
|
||||
@@ -131,7 +133,6 @@ namespace Nuake
|
||||
firstMouse = false;
|
||||
}
|
||||
|
||||
// mouse
|
||||
float diffx = x - mouseLastX;
|
||||
float diffy = mouseLastY - y;
|
||||
mouseLastX = x;
|
||||
@@ -159,31 +160,32 @@ namespace Nuake
|
||||
SetDirection(glm::normalize(Direction));
|
||||
Right = glm::normalize(glm::cross(Up, Direction));
|
||||
|
||||
if (hover)
|
||||
|
||||
if (Input::IsMouseButtonDown(2))
|
||||
{
|
||||
if (Input::IsMouseButtonDown(2))
|
||||
{
|
||||
Vector3 movement = Vector3(0);
|
||||
const float deltaX = x - mouseLastX;
|
||||
const float deltaY = y - mouseLastY;
|
||||
movement += Right * (deltaX * ts);
|
||||
movement += Up * (deltaY * ts);
|
||||
Translation += Vector3(movement) * 0.5f;
|
||||
Vector3 movement = Vector3(0);
|
||||
const float deltaX = x - mouseLastX;
|
||||
const float deltaY = y - mouseLastY;
|
||||
movement += Right * (deltaX * ts);
|
||||
movement += Up * (deltaY * ts);
|
||||
Translation += Vector3(movement) * 0.5f;
|
||||
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
controlled = true;
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
controlled = true;
|
||||
|
||||
SetDirection(glm::normalize(Direction));
|
||||
}
|
||||
else if (Input::YScroll != 0)
|
||||
{
|
||||
Translation += Vector3(Direction) * Input::YScroll;
|
||||
Input::YScroll = 0.0f;
|
||||
}
|
||||
SetDirection(glm::normalize(Direction));
|
||||
}
|
||||
else if (Input::YScroll != 0)
|
||||
{
|
||||
Translation += Vector3(Direction) * Input::YScroll;
|
||||
Input::YScroll = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
SetDirection(glm::normalize(Direction));
|
||||
|
||||
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,11 @@ namespace Nuake
|
||||
{
|
||||
class EditorCamera : public Camera
|
||||
{
|
||||
private:
|
||||
bool m_IsFlying = false;
|
||||
|
||||
public:
|
||||
|
||||
EditorCamera()
|
||||
{
|
||||
Yaw = 0.0f;
|
||||
@@ -27,6 +31,7 @@ namespace Nuake
|
||||
void SetYaw(float yaw);
|
||||
void SetPitch(float pitch);
|
||||
|
||||
bool IsFlying() const { return m_IsFlying; }
|
||||
private:
|
||||
bool controlled = false;
|
||||
bool firstMouse = false;
|
||||
|
||||
@@ -597,10 +597,14 @@ namespace Nuake {
|
||||
});
|
||||
}
|
||||
|
||||
for (int i = 0; i < (face_geo_inst->vertex_count - 2) * 3; ++i)
|
||||
for (int i = 0; i < (face_geo_inst->vertex_count - 2) * 3; i += 3)
|
||||
{
|
||||
uint32_t index = face_geo_inst->indices[i];
|
||||
indices.push_back((unsigned int)index);
|
||||
uint32_t i1 = face_geo_inst->indices[i];
|
||||
uint32_t i2 = face_geo_inst->indices[i + 1];
|
||||
uint32_t i3 = face_geo_inst->indices[i + 2];
|
||||
indices.push_back(i3);
|
||||
indices.push_back(i2);
|
||||
indices.push_back(i1);
|
||||
}
|
||||
|
||||
m_StaticWorld[currentMaterial].push_back({vertices, indices});
|
||||
|
||||
@@ -23,7 +23,8 @@ void main()
|
||||
#shader fragment
|
||||
#version 440 core
|
||||
|
||||
out vec4 FragColor;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(location = 1) out int gEntityID;
|
||||
|
||||
in vec2 a_UV;
|
||||
in mat4 o_Projection;
|
||||
@@ -32,6 +33,7 @@ in vec4 o_FragPos;
|
||||
uniform sampler2D u_DepthTexture;
|
||||
uniform sampler2D gizmo_texture;
|
||||
uniform float u_Opacity;
|
||||
uniform int u_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -41,4 +43,6 @@ void main()
|
||||
color = px_color * vec4(1, 1, 1, u_Opacity);
|
||||
|
||||
FragColor = color;
|
||||
|
||||
gEntityID = int(0);
|
||||
}
|
||||
@@ -21,11 +21,14 @@ void main()
|
||||
|
||||
in vec4 LineColor;
|
||||
|
||||
out vec4 FragColor;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(location = 1) out int gEntityID;
|
||||
|
||||
uniform float u_Opacity;
|
||||
uniform int u_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = LineColor * vec4(1, 1, 1, u_Opacity);
|
||||
gEntityID = int(u_EntityID);
|
||||
}
|
||||
11
premake5.lua
11
premake5.lua
@@ -90,15 +90,16 @@ project "Nuake"
|
||||
}
|
||||
|
||||
filter "system:linux"
|
||||
defines {
|
||||
defines
|
||||
{
|
||||
"GLFW_STATIC",
|
||||
"NK_LINUX"
|
||||
}
|
||||
|
||||
links
|
||||
{
|
||||
"glib-2.0"
|
||||
}
|
||||
{
|
||||
"glib-2.0"
|
||||
}
|
||||
|
||||
buildoptions { "`pkg-config --cflags glib-2.0 pango gdk-pixbuf-2.0 atk`" }
|
||||
linkoptions { "`pkg-config --libs glib-2.0 pango gdk-pixbuf-2.0`" }
|
||||
@@ -107,7 +108,7 @@ project "Nuake"
|
||||
{
|
||||
"/usr/include/gtk-3.0/",
|
||||
"/usr/lib/glib-2.0/include",
|
||||
"/usr/include/glib-2.0",
|
||||
"/usr/include/glib-2.0",
|
||||
}
|
||||
|
||||
filter "system:windows"
|
||||
|
||||
Reference in New Issue
Block a user