mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Various fixes:
- removal of entity crash - play mode corrupt scene graph - Added dither effect on selected entity
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
#include <src/Rendering/Renderer.h>
|
||||
#include "src/UI/UserInterface.h"
|
||||
#include "src/NewEditor.h"
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
|
||||
void OpenProject()
|
||||
{
|
||||
// Parse the project and load it.
|
||||
std::string projectPath = Nuake::FileDialog::OpenFile(".project");
|
||||
std::string projectPath = Nuake::FileDialog::OpenFile("Project file|*.project;");
|
||||
|
||||
Nuake::FileSystem::SetRootDirectory(projectPath + "/../");
|
||||
Ref<Nuake::Project> project = Nuake::Project::New();
|
||||
@@ -55,9 +56,11 @@ int main()
|
||||
Ref<Nuake::Texture> lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png");
|
||||
Ref<Nuake::Texture> camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png");
|
||||
Ref<Nuake::Shader> GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader");
|
||||
Ref<Nuake::Shader> ditherShader = Nuake::ShaderManager::GetShader("resources/Shaders/dither.shader");
|
||||
|
||||
Nuake::NewEditor newEditor = Nuake::NewEditor();
|
||||
//Nuake::NewEditor newEditor = Nuake::NewEditor();
|
||||
|
||||
// Register shaders
|
||||
while (!Nuake::Engine::GetCurrentWindow()->ShouldClose())
|
||||
{
|
||||
Nuake::RenderCommand::Clear();
|
||||
@@ -115,8 +118,23 @@ int main()
|
||||
}
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
GuizmoShader->Unbind();
|
||||
|
||||
ditherShader->Bind();
|
||||
ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
|
||||
ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());
|
||||
ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime());
|
||||
ditherShader->SetUniform4f("u_Color", 252.0 / 255.0, 3.0 / 255.0, 65.0 / 255.0, 1.0);
|
||||
|
||||
if (editor.m_IsEntitySelected && editor.m_SelectedEntity.HasComponent<Nuake::BSPBrushComponent>())
|
||||
{
|
||||
for (auto& m : editor.m_SelectedEntity.GetComponent<Nuake::BSPBrushComponent>().Meshes)
|
||||
Nuake::Renderer::SubmitMesh(m, editor.m_SelectedEntity.GetComponent<Nuake::TransformComponent>().GetTransform());
|
||||
|
||||
Nuake::Renderer::Flush(ditherShader, true);
|
||||
}
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
sceneFramebuffer->Unbind();
|
||||
|
||||
|
||||
32
Editor/resources/Shaders/dither.shader
Normal file
32
Editor/resources/Shaders/dither.shader
Normal file
@@ -0,0 +1,32 @@
|
||||
#shader vertex
|
||||
#version 460 core
|
||||
|
||||
|
||||
layout(location = 0) in vec3 VertexPosition;
|
||||
|
||||
uniform mat4 u_Projection;
|
||||
uniform mat4 u_View;
|
||||
uniform mat4 u_Model;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_Projection * u_View * u_Model * vec4(VertexPosition, 1.0f);
|
||||
}
|
||||
|
||||
#shader fragment
|
||||
#version 460 core
|
||||
|
||||
uniform vec4 u_Color;
|
||||
uniform float u_Time;
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (mod(gl_FragCoord.x + gl_FragCoord.y, 4.0) < 2.0)
|
||||
discard;
|
||||
|
||||
vec4 finalColor = u_Color;
|
||||
finalColor.a = (sin(u_Time * 4.0) + 1.0) / 4.0 + 0.1;
|
||||
FragColor = finalColor;
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ layout(location = 0) in vec3 VertexPosition;
|
||||
uniform mat4 u_Projection;
|
||||
uniform mat4 u_View;
|
||||
uniform mat4 u_Model;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_Projection * u_View * u_Model * vec4(VertexPosition, 1.0f);
|
||||
@@ -16,9 +17,13 @@ void main()
|
||||
#version 460 core
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
if(mod(gl_FragCoord.x / 4.0 + gl_FragCoord.y / 4.0, 4.0) < 2.0)
|
||||
discard;
|
||||
|
||||
FragColor = u_Color;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ float ShadowCalculation(Light light, vec3 FragPos, vec3 normal)
|
||||
int shadowmap = -1;
|
||||
|
||||
// Get CSM depth
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float CSMDepth = light.CascadeDepth[i] ;
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include "UIComponents/Viewport.h"
|
||||
#include <src/Resource/Prefab.h>
|
||||
#include <src/Scene/Components/PrefabComponent.h>
|
||||
#include <src/Rendering/Shaders/ShaderManager.h>
|
||||
#include "src/Rendering/Renderer.h"
|
||||
|
||||
namespace Nuake {
|
||||
Ref<UI::UserInterface> userInterface;
|
||||
@@ -224,7 +226,6 @@ namespace Nuake {
|
||||
if (ImGui::Selectable("Remove")) {
|
||||
|
||||
QueueDeletion = e;
|
||||
open = false;
|
||||
}
|
||||
|
||||
if (ImGui::Selectable("Move to root"))
|
||||
@@ -359,7 +360,7 @@ namespace Nuake {
|
||||
m_SelectedEntity = scene->GetAllEntities().at(0);
|
||||
|
||||
QueueDeletion = Entity{ (entt::entity)0, scene.get() };
|
||||
ImGui::TreePop();
|
||||
//ImGui::TreePop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -453,7 +454,8 @@ namespace Nuake {
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
if (m_SelectedEntity.HasComponent<MeshComponent>()) {
|
||||
if (m_SelectedEntity.HasComponent<MeshComponent>())
|
||||
{
|
||||
std::string icon = ICON_FA_MALE;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Mesh").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
@@ -623,6 +625,7 @@ namespace Nuake {
|
||||
}
|
||||
if (m_SelectedEntity.HasComponent<QuakeMapComponent>())
|
||||
{
|
||||
|
||||
std::string icon = ICON_FA_BROOM;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
@@ -1110,7 +1113,7 @@ namespace Nuake {
|
||||
void OpenProject()
|
||||
{
|
||||
// Parse the project and load it.
|
||||
std::string projectPath = FileDialog::OpenFile(".project");
|
||||
std::string projectPath = FileDialog::OpenFile("Project file\0*.project");
|
||||
|
||||
FileSystem::SetRootDirectory(projectPath + "/../");
|
||||
Ref<Project> project = Project::New();
|
||||
@@ -1124,12 +1127,6 @@ namespace Nuake {
|
||||
Engine::LoadProject(project);
|
||||
|
||||
pInterface.m_CurrentProject = project;
|
||||
// Create new interface named test.
|
||||
//userInterface = UI::UserInterface::New("test");
|
||||
|
||||
|
||||
// Set current interface running.
|
||||
//Engine::GetCurrentScene()->AddInterface(userInterface);
|
||||
}
|
||||
|
||||
void OpenScene()
|
||||
@@ -1138,7 +1135,8 @@ namespace Nuake {
|
||||
std::string projectPath = FileDialog::OpenFile(".scene");
|
||||
|
||||
Ref<Scene> scene = Scene::New();
|
||||
if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) {
|
||||
if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true)))
|
||||
{
|
||||
Logger::Log("Error failed loading scene: " + projectPath, CRITICAL);
|
||||
return;
|
||||
}
|
||||
@@ -1159,15 +1157,16 @@ namespace Nuake {
|
||||
|
||||
if (ImGui::BeginPopupModal("Welcome", NULL, flags))
|
||||
{
|
||||
ImGui::Text("Welcome to");
|
||||
ImGui::Text("Nuake engine");
|
||||
ImGui::Text("Welcome to Nuake Engine");
|
||||
ImGui::Text("Developement build");
|
||||
|
||||
ImGui::Text("Would you like to");
|
||||
if (ImGui::Button("Start a new project"))
|
||||
ImGui::Text("This project is still very early in developement and is not stable!");
|
||||
if (ImGui::Button("New Project"))
|
||||
NewProject();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Open a project")) {
|
||||
if (ImGui::Button("Open Project"))
|
||||
{
|
||||
OpenProject();
|
||||
filesystem.m_CurrentDirectory = FileSystem::RootDirectory;
|
||||
}
|
||||
@@ -1175,10 +1174,10 @@ namespace Nuake {
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (!Engine::GetProject())
|
||||
{
|
||||
ImGui::OpenPopup("Welcome");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Nuake {
|
||||
{
|
||||
private:
|
||||
FileSystemUI filesystem = FileSystemUI();
|
||||
Entity m_SelectedEntity;
|
||||
bool m_IsEntitySelected = false;
|
||||
|
||||
|
||||
bool m_DrawGrid = false;
|
||||
bool m_ShowImGuiDemo = false;
|
||||
bool m_DebugCollisions = false;
|
||||
@@ -27,6 +27,8 @@ namespace Nuake {
|
||||
bool m_IsMaterialSelected = false;
|
||||
|
||||
public:
|
||||
bool m_IsEntitySelected = false;
|
||||
Entity m_SelectedEntity;
|
||||
static ImFont* bigIconFont;
|
||||
void BuildFonts();
|
||||
void Init();
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Nuake
|
||||
float Engine::m_LastFrameTime = 0.0f;
|
||||
float Engine::m_FixedUpdateRate = 1.0 / 144.0f;
|
||||
float Engine::m_FixedUpdateDifference = 0.f;
|
||||
float Engine::m_Time = 0.f;
|
||||
|
||||
bool Engine::IsPlayMode = false;
|
||||
|
||||
void Engine::Init()
|
||||
@@ -41,9 +43,9 @@ namespace Nuake
|
||||
|
||||
void Engine::Tick()
|
||||
{
|
||||
float time = (float)glfwGetTime();
|
||||
Timestep timestep = time - m_LastFrameTime;
|
||||
m_LastFrameTime = time;
|
||||
m_Time = (float)glfwGetTime();
|
||||
Timestep timestep = m_Time - m_LastFrameTime;
|
||||
m_LastFrameTime = m_Time;
|
||||
|
||||
// Dont update if no scene is loaded.
|
||||
if (CurrentWindow->GetScene())
|
||||
@@ -85,7 +87,8 @@ namespace Nuake
|
||||
void Engine::ExitPlayMode()
|
||||
{
|
||||
// Dont trigger exit if already not in play mode.
|
||||
if (IsPlayMode) {
|
||||
if (IsPlayMode)
|
||||
{
|
||||
GetCurrentScene()->OnExit();
|
||||
Input::ShowMouse();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Nuake
|
||||
static float m_LastFrameTime;
|
||||
static float m_FixedUpdateRate;
|
||||
static float m_FixedUpdateDifference;
|
||||
static float m_Time;
|
||||
public:
|
||||
static bool IsPlayMode; // Is currently in runtime..
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace Nuake
|
||||
// Custom drawing should happen in between these two
|
||||
static void Draw(); // Start new frame
|
||||
static void EndDraw(); // Swap buffer
|
||||
|
||||
static inline float GetTime() { return m_Time; }
|
||||
static Ref<Window> GetCurrentWindow();
|
||||
|
||||
static bool LoadScene(Ref<Scene> scene);
|
||||
|
||||
@@ -260,7 +260,6 @@ namespace Nuake {
|
||||
env->Push();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Register the lights
|
||||
@@ -421,10 +420,7 @@ namespace Nuake {
|
||||
|
||||
for (auto& b : model.Meshes)
|
||||
{
|
||||
AABB aabb = b->GetAABB();
|
||||
aabb.Transform(transform.GetTransform());
|
||||
if (m_EditorCamera->BoxFrustumCheck(aabb))
|
||||
Renderer::SubmitMesh(b, transform.GetTransform());
|
||||
Renderer::SubmitMesh(b, transform.GetTransform());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,12 @@ namespace Nuake
|
||||
PhysicsManager::Get()->Step(ts);
|
||||
|
||||
auto brushes = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent>();
|
||||
for (auto e : brushes) {
|
||||
for (auto e : brushes)
|
||||
{
|
||||
auto [transform, brush] = brushes.get<TransformComponent, BSPBrushComponent>(e);
|
||||
|
||||
for (auto& r : brush.Rigidbody) {
|
||||
for (auto& r : brush.Rigidbody)
|
||||
{
|
||||
r->m_Transform->setOrigin(btVector3(transform.GlobalTranslation.x, transform.GlobalTranslation.y, transform.GlobalTranslation.z));
|
||||
r->UpdateTransform(*r->m_Transform);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Nuake {
|
||||
Vector3 globalScale = Vector3();
|
||||
if (parent.HasParent)
|
||||
{
|
||||
ParentComponent& parentComponent = currentParent.GetComponent<ParentComponent>();
|
||||
ParentComponent parentComponent = currentParent.GetComponent<ParentComponent>();
|
||||
while (parentComponent.HasParent)
|
||||
{
|
||||
TransformComponent& transformComponent = parentComponent.Parent.GetComponent<TransformComponent>();
|
||||
@@ -68,6 +68,7 @@ namespace Nuake {
|
||||
transform.GlobalTranslation = globalPosition + transform.Translation;
|
||||
transform.GlobalRotation = globalRotation + transform.Rotation;
|
||||
transform.GlobalScale = globalScale * transform.Scale;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user