mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Merge branch 'main' of https://github.com/antopilo/Nuake
This commit is contained in:
@@ -23,7 +23,6 @@ void main()
|
||||
//T = normalize(T - dot(T, N) * N);
|
||||
//vec3 B = cross(N, T);
|
||||
|
||||
|
||||
vec3 T = normalize((u_Model * vec4(Tangent, 0.0f)).xyz);
|
||||
vec3 N = normalize((u_Model * vec4(Normal, 0.0f)).xyz);
|
||||
vec3 B = normalize((u_Model * vec4(Bitangent, 0.0f)).xyz);
|
||||
@@ -83,10 +82,17 @@ void main()
|
||||
// Albedo
|
||||
gAlbedo = vec4(m_AlbedoColor, 1.0);
|
||||
if (u_HasAlbedo == 1)
|
||||
gAlbedo.rgb = texture(m_Albedo, UV).rgb;
|
||||
{
|
||||
vec4 albedoSample = texture(m_Albedo, UV);
|
||||
gAlbedo.rgb = albedoSample.rgb * m_AlbedoColor.rgb;
|
||||
gAlbedo.a = albedoSample.a;
|
||||
|
||||
if (albedoSample.a < 0.1f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
gAlbedo.rgb = texture(m_Albedo, UV).rgb * m_AlbedoColor.rgb;
|
||||
|
||||
// Material
|
||||
float finalMetalness = u_MetalnessValue;
|
||||
if (u_HasMetalness == 1)
|
||||
|
||||
73
Editor/src/ComponentsPanel/SpritePanel.h
Normal file
73
Editor/src/ComponentsPanel/SpritePanel.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
#include "ComponentPanel.h"
|
||||
|
||||
#include <src/Core/FileSystem.h>
|
||||
#include <src/Core/Maths.h>
|
||||
#include <src/Scene/Components/SpriteComponent.h>
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
|
||||
|
||||
class SpritePanel : ComponentPanel
|
||||
{
|
||||
public:
|
||||
SpritePanel() = default;
|
||||
~SpritePanel() = default;
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
if (!entity.HasComponent<Nuake::SpriteComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto& component = entity.GetComponent<Nuake::SpriteComponent>();
|
||||
BeginComponentTable(SPRITE, Nuake::SpriteComponent);
|
||||
{
|
||||
{
|
||||
ImGui::Text("Sprite");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
std::string path = component.SpritePath;
|
||||
ImGui::Button(path.empty() ? "Drag image" : component.SpritePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0));
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Image"))
|
||||
{
|
||||
char* file = (char*)payload->Data;
|
||||
|
||||
std::string fullPath = std::string(file, 512);
|
||||
path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath));
|
||||
component.SpritePath = path;
|
||||
|
||||
component.LoadSprite();
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.LockYRotation, false);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Billboard");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##billboard", &component.Billboard);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ComponentTableReset(component.Billboard, false);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Lock Y rotation");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##lockYRotation", &component.LockYRotation);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ComponentTableReset(component.LockYRotation, false);
|
||||
}
|
||||
}
|
||||
EndComponentTable();
|
||||
}
|
||||
};
|
||||
@@ -14,13 +14,6 @@
|
||||
|
||||
EditorSelectionPanel::EditorSelectionPanel()
|
||||
{
|
||||
mTransformPanel = TransformPanel();
|
||||
mLightPanel = LightPanel();
|
||||
mScriptPanel = ScriptPanel();
|
||||
mQuakeMapPanel = QuakeMapPanel();
|
||||
mCameraPanel = CameraPanel();
|
||||
mRigidbodyPanel = RigidbodyPanel();
|
||||
mBoxColliderPanel = BoxColliderPanel();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
|
||||
@@ -100,6 +93,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
mTransformPanel.Draw(entity);
|
||||
mLightPanel.Draw(entity);
|
||||
mScriptPanel.Draw(entity);
|
||||
mSpritePanel.Draw(entity);
|
||||
mMeshPanel.Draw(entity);
|
||||
mQuakeMapPanel.Draw(entity);
|
||||
mCameraPanel.Draw(entity);
|
||||
@@ -129,6 +123,7 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
MenuItemComponent("Camera", Nuake::CameraComponent)
|
||||
MenuItemComponent("Light", Nuake::LightComponent)
|
||||
MenuItemComponent("Model", Nuake::ModelComponent)
|
||||
MenuItemComponent("Sprite", Nuake::SpriteComponent)
|
||||
ImGui::Separator();
|
||||
MenuItemComponent("Character Controller", Nuake::CharacterControllerComponent)
|
||||
MenuItemComponent("Rigid body", Nuake::RigidBodyComponent)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "../ComponentsPanel/SphereColliderPanel.h"
|
||||
#include "../ComponentsPanel/MeshColliderPanel.h"
|
||||
#include "../ComponentsPanel/CharacterControllerPanel.h"
|
||||
#include "../ComponentsPanel/SpritePanel.h"
|
||||
|
||||
|
||||
class EditorSelectionPanel {
|
||||
private:
|
||||
@@ -33,7 +35,7 @@ private:
|
||||
MeshColliderPanel mMeshColliderPanel;
|
||||
CapsuleColliderPanel mCapsuleColliderPanel;
|
||||
CylinderColliderPanel mCylinderColliderPanel;
|
||||
|
||||
SpritePanel mSpritePanel;
|
||||
CharacterControllerPanel mCharacterControllerPanel;
|
||||
|
||||
Ref<Nuake::File> currentFile;
|
||||
|
||||
@@ -211,28 +211,42 @@ namespace Nuake
|
||||
{
|
||||
Editor->Selection = EditorSelection(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::BeginDragDropSource())
|
||||
if (ImGui::BeginDragDropSource())
|
||||
{
|
||||
char pathBuffer[256];
|
||||
std::strncpy(pathBuffer, file->GetAbsolutePath().c_str(), sizeof(pathBuffer));
|
||||
std::string dragType;
|
||||
if (fileExtension == ".wren")
|
||||
{
|
||||
dragType = "_Script";
|
||||
}
|
||||
else if (fileExtension == ".map")
|
||||
{
|
||||
dragType = "_Map";
|
||||
}
|
||||
else if (fileExtension == ".obj" || fileExtension == ".mdl" || fileExtension == ".gltf" || fileExtension == ".md3" || fileExtension == ".fbx")
|
||||
{
|
||||
dragType = "_Model";
|
||||
}
|
||||
else if (fileExtension == ".interface")
|
||||
{
|
||||
dragType = "_Interface";
|
||||
}
|
||||
else if (fileExtension == ".prefab")
|
||||
{
|
||||
dragType = "_Prefab";
|
||||
}
|
||||
else if (fileExtension == ".png" || fileExtension == ".jpg")
|
||||
{
|
||||
dragType = "_Image";
|
||||
}
|
||||
|
||||
ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer));
|
||||
ImGui::Text(file->GetName().c_str());
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
}
|
||||
|
||||
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
|
||||
@@ -532,8 +546,6 @@ namespace Nuake
|
||||
ImGui::EndChild();
|
||||
ImGui::SameLine();
|
||||
|
||||
avail = ImGui::GetContentRegionAvail();
|
||||
|
||||
std::vector<Ref<Directory>> paths = std::vector<Ref<Directory>>();
|
||||
|
||||
Ref<Directory> currentParent = m_CurrentDirectory;
|
||||
@@ -581,12 +593,13 @@ namespace Nuake
|
||||
}
|
||||
|
||||
const uint32_t numButtonAfterPathBrowser = 2;
|
||||
const uint32_t searchBarSize = 6;
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4));
|
||||
ImGui::BeginChild("pathBrowser", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth) - 4.0, 24));
|
||||
ImGui::BeginChild("pathBrowser", ImVec2((ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth * searchBarSize)) - 4.0, 24));
|
||||
for (int i = paths.size() - 1; i > 0; i--)
|
||||
{
|
||||
if (i != paths.size())
|
||||
@@ -610,13 +623,23 @@ namespace Nuake
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("/");
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginChild("searchBar", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth), 24));
|
||||
char buffer[256];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer));
|
||||
if (ImGui::InputTextEx("##Search", "Asset search & filter ..", buffer, sizeof(buffer), ImVec2(ImGui::GetContentRegionAvail().x, 24), ImGuiInputTextFlags_EscapeClearsAll))
|
||||
{
|
||||
m_searchKeyWord = std::string(buffer);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
@@ -633,8 +656,9 @@ namespace Nuake
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(); // Button color
|
||||
|
||||
ImGui::SameLine();
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
@@ -668,13 +692,16 @@ namespace Nuake
|
||||
{
|
||||
for (Ref<Directory>& d : m_CurrentDirectory->Directories)
|
||||
{
|
||||
if (i + 1 % amount != 0)
|
||||
ImGui::TableNextColumn();
|
||||
else
|
||||
ImGui::TableNextRow();
|
||||
if(String::Sanitize(d->name).find(String::Sanitize(m_searchKeyWord)) != std::string::npos)
|
||||
{
|
||||
if (i + 1 % amount != 0)
|
||||
ImGui::TableNextColumn();
|
||||
else
|
||||
ImGui::TableNextRow();
|
||||
|
||||
DrawDirectory(d, i);
|
||||
i++;
|
||||
DrawDirectory(d, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,13 +709,16 @@ namespace Nuake
|
||||
{
|
||||
for (auto f : m_CurrentDirectory->Files)
|
||||
{
|
||||
if (i - 1 % amount != 0 || i == 1)
|
||||
ImGui::TableNextColumn();
|
||||
else
|
||||
ImGui::TableNextRow();
|
||||
if(String::Sanitize(f->GetName()).find(String::Sanitize(m_searchKeyWord)) != std::string::npos)
|
||||
{
|
||||
if (i - 1 % amount != 0 || i == 1)
|
||||
ImGui::TableNextColumn();
|
||||
else
|
||||
ImGui::TableNextRow();
|
||||
|
||||
DrawFile(f, i);
|
||||
i++;
|
||||
DrawFile(f, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Nuake {
|
||||
public:
|
||||
static Ref<Directory> m_CurrentDirectory;
|
||||
bool m_hasClickedOnFile;
|
||||
std::string m_searchKeyWord;
|
||||
|
||||
FileSystemUI(EditorInterface* editor)
|
||||
{
|
||||
|
||||
@@ -70,19 +70,15 @@ namespace Nuake
|
||||
|
||||
newDir->Parent = directory;
|
||||
ScanDirectory(newDir);
|
||||
|
||||
directory->Directories.push_back(newDir);
|
||||
}
|
||||
else if (entry.is_regular_file())
|
||||
{
|
||||
std::string absolutePath = entry.path().string();
|
||||
std::string name = entry.path().filename().string();
|
||||
std::string extension = entry.path().extension().string();
|
||||
std::filesystem::path currentPath = entry.path();
|
||||
std::string absolutePath = currentPath.string();
|
||||
std::string name = currentPath.filename().string();
|
||||
std::string extension = currentPath.extension().string();
|
||||
Ref<File> newFile = CreateRef<File>(directory, absolutePath, name, extension);
|
||||
//newFile->Type = entry.path().extension().string();
|
||||
//newFile->name = entry.path().filename().string();
|
||||
//newFile->Parent = directory;
|
||||
//newFile->fullPath = entry.path().string();
|
||||
directory->Files.push_back(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "String.h"
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
namespace Nuake
|
||||
@@ -36,6 +37,19 @@ namespace Nuake
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string String::Sanitize(const std::string& keyword)
|
||||
{
|
||||
std::string sanitizedKeyword = keyword;
|
||||
|
||||
// Remove spaces, underscores, and hyphens using regex
|
||||
sanitizedKeyword = std::regex_replace(sanitizedKeyword, std::regex("[ _-]+"), "");
|
||||
|
||||
// Convert to lowercase
|
||||
std::transform(sanitizedKeyword.begin(), sanitizedKeyword.end(), sanitizedKeyword.begin(), ::tolower);
|
||||
|
||||
return sanitizedKeyword;
|
||||
}
|
||||
|
||||
std::vector<std::string> String::Split(const std::string& string, char delimiter)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Nuake
|
||||
static bool EndsWith(const std::string& string, const std::string& end);
|
||||
static bool IsDigit(const char& character);
|
||||
static std::string RemoveWhiteSpace(const std::string& string);
|
||||
static std::string Sanitize(const std::string& keyword);
|
||||
static std::vector<std::string> Split(const std::string& string, char delimiter);
|
||||
|
||||
static float ToFloat(const std::string& string);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Nuake
|
||||
unsigned int depthFBO;
|
||||
|
||||
Ref<Mesh> Renderer::CubeMesh;
|
||||
Ref<Mesh> Renderer::QuadMesh;
|
||||
|
||||
Shader* Renderer::m_Shader;
|
||||
Shader* Renderer::m_SkyboxShader;
|
||||
@@ -62,13 +63,14 @@ namespace Nuake
|
||||
4, 5, 0, 0, 5, 1
|
||||
};
|
||||
|
||||
float QuadVertices[] = {
|
||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f
|
||||
std::vector<Vertex> QuadVertices
|
||||
{
|
||||
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0.0f, 0.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) }
|
||||
};
|
||||
|
||||
|
||||
@@ -84,24 +86,10 @@ namespace Nuake
|
||||
CubeMesh = CreateRef<Mesh>();
|
||||
CubeMesh->AddSurface(CubeVertices, CubeIndices);
|
||||
CubeMesh->SetMaterial(material);
|
||||
// Cube buffer
|
||||
//CubeVertexArray = new VertexArray();
|
||||
//CubeVertexArray->Bind();
|
||||
//CubeVertexBuffer = new VertexBuffer(CubeVertices, sizeof(CubeVertices));
|
||||
//
|
||||
VertexBufferLayout vblayout = VertexBufferLayout();
|
||||
vblayout.Push<float>(3);
|
||||
//CubeVertexArray->AddBuffer(*CubeVertexBuffer, vblayout);
|
||||
|
||||
// Quad buffer
|
||||
QuadVertexArray = new VertexArray();
|
||||
QuadVertexArray->Bind();
|
||||
QuadVertexBuffer = new VertexBuffer(QuadVertices, sizeof(QuadVertices));
|
||||
|
||||
vblayout = VertexBufferLayout();
|
||||
vblayout.Push<float>(3);
|
||||
vblayout.Push<float>(2);
|
||||
QuadVertexArray->AddBuffer(*QuadVertexBuffer, vblayout);
|
||||
QuadMesh = CreateRef<Mesh>();
|
||||
QuadMesh->AddSurface(QuadVertices, { 0, 1, 2, 3, 4, 5 });
|
||||
QuadMesh->SetMaterial(material);
|
||||
}
|
||||
|
||||
void Renderer::LoadShaders()
|
||||
@@ -221,7 +209,7 @@ namespace Nuake
|
||||
m_DebugShader->SetUniformMat4f("u_Model", transform.GetGlobalTransform());
|
||||
m_DebugShader->SetUniform4f("u_Color", color.r, color.g, color.b, color.a);
|
||||
|
||||
CubeVertexArray->Bind();
|
||||
CubeMesh->Bind();
|
||||
RenderCommand::DrawArrays(0, 36);
|
||||
}
|
||||
|
||||
@@ -233,7 +221,7 @@ namespace Nuake
|
||||
|
||||
void Renderer::DrawQuad(Matrix4 transform)
|
||||
{
|
||||
QuadVertexArray->Bind();
|
||||
QuadMesh->Bind();
|
||||
RenderCommand::DrawArrays(0, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Nuake
|
||||
{
|
||||
private:
|
||||
static RenderList m_RenderList;
|
||||
|
||||
public:
|
||||
static VertexArray* QuadVertexArray;
|
||||
static VertexBuffer* QuadVertexBuffer;
|
||||
@@ -51,6 +52,7 @@ namespace Nuake
|
||||
static Ref<UniformBuffer> m_LightsUniformBuffer;
|
||||
|
||||
static Ref<Mesh> CubeMesh;
|
||||
static Ref<Mesh> QuadMesh;
|
||||
|
||||
static void Init();
|
||||
static void LoadShaders();
|
||||
@@ -65,7 +67,6 @@ namespace Nuake
|
||||
|
||||
// Lights
|
||||
static std::vector<Light> m_Lights;
|
||||
static void RegisterLight(TransformComponent transform, LightComponent light);
|
||||
static void RegisterDeferredLight(TransformComponent transform, LightComponent light);
|
||||
|
||||
// Debug
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "SceneRenderer.h"
|
||||
#include "src/Rendering/Shaders/ShaderManager.h"
|
||||
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
#include "src/Scene/Components/BSPBrushComponent.h"
|
||||
#include "src/Scene/Components/SpriteComponent.h"
|
||||
|
||||
#include <GL\glew.h>
|
||||
|
||||
namespace Nuake
|
||||
@@ -240,16 +242,18 @@ namespace Nuake
|
||||
mGBuffer->Bind();
|
||||
mGBuffer->Clear();
|
||||
{
|
||||
// Init
|
||||
RenderCommand::Enable(RendererEnum::FACE_CULL);
|
||||
Shader* gBufferShader = ShaderManager::GetShader("resources/Shaders/gbuffer.shader");
|
||||
gBufferShader->Bind();
|
||||
gBufferShader->SetUniformMat4f("u_Projection", mProjection);
|
||||
gBufferShader->SetUniformMat4f("u_View", mView);
|
||||
|
||||
auto view = scene.m_Registry.view<TransformComponent, ModelComponent, ParentComponent, VisibilityComponent>();
|
||||
// Models
|
||||
auto view = scene.m_Registry.view<TransformComponent, ModelComponent, VisibilityComponent>();
|
||||
for (auto e : view)
|
||||
{
|
||||
auto [transform, mesh, parent, visibility] = view.get<TransformComponent, ModelComponent, ParentComponent, VisibilityComponent>(e);
|
||||
auto [transform, mesh, visibility] = view.get<TransformComponent, ModelComponent, VisibilityComponent>(e);
|
||||
|
||||
if (mesh.ModelResource && visibility.Visible)
|
||||
{
|
||||
@@ -264,10 +268,11 @@ namespace Nuake
|
||||
RenderCommand::Disable(RendererEnum::FACE_CULL);
|
||||
Renderer::Flush(gBufferShader, false);
|
||||
|
||||
auto quakeView = scene.m_Registry.view<TransformComponent, BSPBrushComponent, ParentComponent, VisibilityComponent>();
|
||||
// Quake BSPs
|
||||
auto quakeView = scene.m_Registry.view<TransformComponent, BSPBrushComponent, VisibilityComponent>();
|
||||
for (auto e : quakeView)
|
||||
{
|
||||
auto [transform, model, parent, visibility] = quakeView.get<TransformComponent, BSPBrushComponent, ParentComponent, VisibilityComponent>(e);
|
||||
auto [transform, model, visibility] = quakeView.get<TransformComponent, BSPBrushComponent, VisibilityComponent>(e);
|
||||
|
||||
if (model.IsTransparent || !visibility.Visible)
|
||||
continue;
|
||||
@@ -278,6 +283,39 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
Renderer::Flush(gBufferShader, false);
|
||||
|
||||
// Sprites
|
||||
auto spriteView = scene.m_Registry.view<TransformComponent, SpriteComponent, VisibilityComponent>();
|
||||
for (auto e : spriteView)
|
||||
{
|
||||
auto [transform, sprite, visibility] = spriteView.get<TransformComponent, SpriteComponent, VisibilityComponent>(e);
|
||||
|
||||
if (!visibility.Visible || !sprite.SpriteMesh)
|
||||
continue;
|
||||
|
||||
auto& finalQuadTransform = transform.GetGlobalTransform();
|
||||
if (sprite.Billboard)
|
||||
{
|
||||
finalQuadTransform = glm::inverse(mView);
|
||||
|
||||
if (sprite.LockYRotation)
|
||||
{
|
||||
// This locks the pitch rotation on the billboard, useful for trees, lamps, etc.
|
||||
finalQuadTransform[1] = Vector4(0, 1, 0, 0);
|
||||
finalQuadTransform[2] = Vector4(finalQuadTransform[2][0], 0, finalQuadTransform[2][2], 0);
|
||||
finalQuadTransform = finalQuadTransform;
|
||||
}
|
||||
|
||||
// Translation
|
||||
finalQuadTransform[3] = Vector4(transform.GetGlobalPosition(), 1.0f);
|
||||
|
||||
// Scale
|
||||
finalQuadTransform = glm::scale(finalQuadTransform, transform.GetGlobalScale());
|
||||
}
|
||||
|
||||
Renderer::SubmitMesh(sprite.SpriteMesh, finalQuadTransform, (uint32_t)e);
|
||||
}
|
||||
Renderer::Flush(gBufferShader, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace Nuake
|
||||
|
||||
Source = newSource;
|
||||
ProgramId = newProgramId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bind the shader
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace Nuake
|
||||
|
||||
void LoadMaterials();
|
||||
|
||||
|
||||
void RegisterMaterial(Ref<Material> material);
|
||||
|
||||
Ref<Material> LoadMaterial(std::string path);
|
||||
|
||||
70
Nuake/src/Scene/Components/SpriteComponent.cpp
Normal file
70
Nuake/src/Scene/Components/SpriteComponent.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "SpriteComponent.h"
|
||||
|
||||
#include "src/Core/FileSystem.h"
|
||||
#include "src/Rendering/Textures/TextureManager.h"
|
||||
#include "src/Rendering/Textures/MaterialManager.h"
|
||||
#include "src/Rendering/Vertex.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
SpriteComponent::SpriteComponent() :
|
||||
Billboard(false),
|
||||
LockYRotation(false),
|
||||
SpritePath("")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool SpriteComponent::LoadSprite()
|
||||
{
|
||||
std::vector<Vertex> quadVertices =
|
||||
{
|
||||
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0, 0), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(-1.0f, 1.0f, 0.0f), Vector2(0.0f, 1.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, -1.0f, 0.0f), Vector2(1.0f, 0.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(-1.0f, -1.0f, 0.0f), Vector2(0.0f, 0.0f), Vector3(0, 0, -1) },
|
||||
{ Vector3(1.0f, 1.0f, 0.0f), Vector2(1.0f, 1.0f), Vector3(0, 0, -1) }
|
||||
};
|
||||
|
||||
SpriteMesh = CreateRef<Mesh>();
|
||||
SpriteMesh->AddSurface(quadVertices, { 0, 1, 2, 3, 4, 5 });
|
||||
|
||||
auto& material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath);
|
||||
SpriteMesh->SetMaterial(material);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
json SpriteComponent::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Billboard)
|
||||
SERIALIZE_VAL(LockYRotation)
|
||||
SERIALIZE_VAL(SpritePath)
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool SpriteComponent::Deserialize(const std::string& str)
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
|
||||
if (j.contains("Billboard"))
|
||||
{
|
||||
Billboard = j["Billboard"];
|
||||
}
|
||||
|
||||
if (j.contains("LockYRotation"))
|
||||
{
|
||||
LockYRotation = j["LockYRotation"];
|
||||
}
|
||||
|
||||
if (j.contains("SpritePath"))
|
||||
{
|
||||
SpritePath = j["SpritePath"];
|
||||
LoadSprite();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
25
Nuake/src/Scene/Components/SpriteComponent.h
Normal file
25
Nuake/src/Scene/Components/SpriteComponent.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Resource/Serializable.h"
|
||||
#include "src/Rendering/Textures/Texture.h"
|
||||
#include "src/Rendering/Mesh/Mesh.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class SpriteComponent
|
||||
{
|
||||
public:
|
||||
bool Billboard;
|
||||
bool LockYRotation;
|
||||
std::string SpritePath;
|
||||
Ref<Mesh> SpriteMesh;
|
||||
|
||||
SpriteComponent();
|
||||
|
||||
public:
|
||||
bool LoadSprite();
|
||||
|
||||
json Serialize();
|
||||
bool Deserialize(const std::string& str);
|
||||
};
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
#include "../Components/ParentComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "../Components/NameComponent.h"
|
||||
#include "../Components/TransformComponent.h"
|
||||
#include "../Components/CameraComponent.h"
|
||||
#include "../Components/QuakeMap.h"
|
||||
#include "../Components/LightComponent.h"
|
||||
#include "../Components/QuakeMap.h"
|
||||
#include "../Components/WrenScriptComponent.h"
|
||||
#include "../Components/CharacterControllerComponent.h"
|
||||
#include "../Components/RigidbodyComponent.h"
|
||||
#include "src/Scene/Components/BSPBrushComponent.h"
|
||||
|
||||
#include "src/Scene/Components/ParentComponent.h"
|
||||
#include "src/Scene/Components/NameComponent.h"
|
||||
#include "src/Scene/Components/TransformComponent.h"
|
||||
#include "src/Scene/Components/CameraComponent.h"
|
||||
#include "src/Scene/Components/QuakeMap.h"
|
||||
#include "src/Scene/Components/LightComponent.h"
|
||||
#include "src/Scene/Components/QuakeMap.h"
|
||||
#include "src/Scene/Components/WrenScriptComponent.h"
|
||||
#include "src/Scene/Components/CharacterControllerComponent.h"
|
||||
#include "src/Scene/Components/RigidbodyComponent.h"
|
||||
#include "src/Scene/Components/BSPBrushComponent.h"
|
||||
#include "src/Scene/Components/Components.h"
|
||||
#include <src/Scene/Components/BoxCollider.h>
|
||||
#include "src/Scene/Components/BoxCollider.h"
|
||||
#include "src/Scene/Components/CapsuleColliderComponent.h"
|
||||
#include "src/Scene/Components/SpriteComponent.h"
|
||||
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -37,6 +39,8 @@ namespace Nuake
|
||||
SERIALIZE_OBJECT_REF_LBL("VisibilityComponent", GetComponent<VisibilityComponent>())
|
||||
if (HasComponent<CameraComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent<CameraComponent>())
|
||||
if (HasComponent<SpriteComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("SpriteComponent", GetComponent<SpriteComponent>())
|
||||
if (HasComponent<QuakeMapComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("QuakeMapComponent", GetComponent<QuakeMapComponent>())
|
||||
if (HasComponent<LightComponent>())
|
||||
@@ -78,6 +82,7 @@ namespace Nuake
|
||||
}
|
||||
DESERIALIZE_COMPONENT(NameComponent)
|
||||
DESERIALIZE_COMPONENT(ParentComponent)
|
||||
DESERIALIZE_COMPONENT(SpriteComponent)
|
||||
DESERIALIZE_COMPONENT(CameraComponent)
|
||||
DESERIALIZE_COMPONENT(QuakeMapComponent)
|
||||
DESERIALIZE_COMPONENT(LightComponent)
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Nuake
|
||||
SetWindowIcon("resources/Images/nuake-logo.png");
|
||||
|
||||
glfwMakeContextCurrent(m_Window);
|
||||
//SetVSync(true)
|
||||
SetVSync(true);
|
||||
|
||||
Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "renderer");
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace Nuake
|
||||
|
||||
void Window::SetVSync(bool enabled)
|
||||
{
|
||||
glfwSwapInterval(enabled ? 0 : 1);
|
||||
glfwSwapInterval(enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
void Window::SetDecorated(bool enabled)
|
||||
|
||||
Reference in New Issue
Block a user