Serialization work
This commit is contained in:
@@ -181,7 +181,7 @@ int main()
|
||||
EditorInterface editor;
|
||||
editor.BuildFonts();
|
||||
|
||||
CreateScene();
|
||||
//CreateScene();
|
||||
|
||||
while (!Engine::GetCurrentWindow()->ShouldClose())
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <src/Scene/Entities/Components/BoxCollider.h>
|
||||
#include <algorithm>
|
||||
#include <Dependencies/GLEW/include/GL/glew.h>
|
||||
#include "src/Resource/Project.h"
|
||||
|
||||
ImFont* normalFont;
|
||||
ImFont* bigIconFont;
|
||||
@@ -180,6 +181,8 @@ void EditorInterface::DrawSceneTree()
|
||||
{
|
||||
Ref<Scene> scene = Engine::GetCurrentScene();
|
||||
|
||||
if (!scene)
|
||||
return;
|
||||
if (ImGui::Begin("Environnement"))
|
||||
{
|
||||
auto env = Engine::GetCurrentScene()->GetEnvironment();
|
||||
@@ -842,13 +845,36 @@ void EditorInterface::Draw()
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("New project", "CTRL+N")) {}
|
||||
if (ImGui::MenuItem("Open...", "CTRL+O")) {
|
||||
FileDialog::OpenFile(".project");
|
||||
if (ImGui::MenuItem("New project", "CTRL+N"))
|
||||
{
|
||||
if(Engine::GetProject())
|
||||
Engine::GetProject()->Save();
|
||||
|
||||
// Parse the project and load it.
|
||||
std::string selectedProject = FileDialog::SaveFile(".project") + ".project";
|
||||
|
||||
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject);
|
||||
Engine::LoadProject(project);
|
||||
|
||||
Ref<Scene> scene = Scene::New();
|
||||
Engine::LoadScene(scene);
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "CTRL+S")) {}
|
||||
if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S")) {
|
||||
FileDialog::SaveFile(".project");
|
||||
if (ImGui::MenuItem("Open...", "CTRL+O"))
|
||||
{
|
||||
// Parse the project and load it.
|
||||
std::string selectedProject = FileDialog::OpenFile(".project");
|
||||
Ref<Project> project = Project::Load(selectedProject);
|
||||
Engine::LoadProject(project);
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "CTRL+S"))
|
||||
{
|
||||
Engine::GetProject()->Save();
|
||||
Engine::GetCurrentScene()->Save();
|
||||
}
|
||||
if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S"))
|
||||
{
|
||||
std::string savePath = FileDialog::SaveFile("*.project");
|
||||
Engine::GetProject()->SaveAs(savePath);
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -7,20 +7,24 @@ float Engine::m_LastFrameTime = 0.0f;
|
||||
Ref<Window> Engine::CurrentWindow;
|
||||
bool Engine::IsPlayMode = false;
|
||||
|
||||
Ref<Project> Engine::CurrentProject;
|
||||
|
||||
#include "../Rendering/Renderer.h"
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
void Engine::Init()
|
||||
{
|
||||
|
||||
PhysicsManager::Get()->Init();
|
||||
FileSystem::Scan();
|
||||
|
||||
CurrentWindow = std::make_shared<Window>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Engine::Tick()
|
||||
{
|
||||
if (!CurrentWindow->GetScene())
|
||||
return;
|
||||
|
||||
float time = (float)glfwGetTime();
|
||||
Timestep timestep = time - m_LastFrameTime;
|
||||
m_LastFrameTime = time;
|
||||
@@ -49,6 +53,11 @@ void Engine::ExitPlayMode()
|
||||
|
||||
void Engine::Draw()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
Window::Get()->Draw();
|
||||
}
|
||||
|
||||
@@ -72,6 +81,27 @@ Ref<Scene> Engine::GetCurrentScene()
|
||||
return CurrentWindow->GetScene();
|
||||
}
|
||||
|
||||
bool Engine::LoadScene(Ref<Scene> scene)
|
||||
{
|
||||
CurrentWindow->SetScene(scene);
|
||||
return true;
|
||||
}
|
||||
|
||||
Ref<Project> Engine::GetProject()
|
||||
{
|
||||
return CurrentProject;
|
||||
}
|
||||
|
||||
bool Engine::LoadProject(Ref<Project> project)
|
||||
{
|
||||
CurrentProject = project;
|
||||
|
||||
Ref<Scene> newScene = CreateRef<Scene>();
|
||||
Engine::LoadScene(newScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Engine::HelloWorld()
|
||||
{
|
||||
return 1;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Window.h"
|
||||
#include "src/Scene/Scene.h"
|
||||
#include "src/Resource/Project.h"
|
||||
|
||||
|
||||
class __declspec(dllexport) Engine {
|
||||
class Engine {
|
||||
private:
|
||||
static float m_LastFrameTime;
|
||||
static Ref<Window> CurrentWindow;
|
||||
|
||||
static Ref<Project> CurrentProject;
|
||||
|
||||
public:
|
||||
static bool IsPlayMode;
|
||||
@@ -26,4 +26,8 @@ public:
|
||||
static int HelloWorld();
|
||||
static Ref<Window> GetCurrentWindow();
|
||||
static Ref<Scene> GetCurrentScene();
|
||||
static bool LoadScene(Ref<Scene> scene);
|
||||
|
||||
static Ref<Project> GetProject();
|
||||
static bool LoadProject(Ref<Project> project);
|
||||
};
|
||||
@@ -30,7 +30,6 @@ std::string FileDialog::OpenFile(const char* filter)
|
||||
return std::string();
|
||||
|
||||
}
|
||||
|
||||
std::string FileDialog::SaveFile(const char* filter)
|
||||
{
|
||||
|
||||
@@ -51,11 +50,9 @@ std::string FileDialog::SaveFile(const char* filter)
|
||||
return std::string();
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string FileSystem::Root = "resources\\";
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
void FileSystem::ScanDirectory(Ref<Directory> directory)
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(directory->fullPath))
|
||||
@@ -82,7 +79,10 @@ void FileSystem::ScanDirectory(Ref<Directory> directory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSystem::DirectoryExists(const std::string path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
void FileSystem::Scan()
|
||||
{
|
||||
RootDirectory = CreateRef<Directory>();
|
||||
|
||||
@@ -37,7 +37,12 @@ public:
|
||||
static Ref<Directory> RootDirectory;
|
||||
|
||||
static void Scan();
|
||||
static Ref<Directory> GetFileTree();
|
||||
static void ScanDirectory(Ref<Directory> directory);
|
||||
static void GetDirectories();
|
||||
static Ref<Directory> GetFileTree();
|
||||
|
||||
static bool DirectoryExists(const std::string path);
|
||||
static bool FileExists(const std::string path);
|
||||
|
||||
|
||||
};
|
||||
@@ -7,7 +7,7 @@ namespace Physics {
|
||||
enum RigidbodyShapes {
|
||||
BOX, SPHERE, CAPSULE, MESH
|
||||
};
|
||||
class __declspec(dllexport) PhysicShape {
|
||||
class PhysicShape {
|
||||
protected:
|
||||
btCollisionShape* bShape;
|
||||
RigidbodyShapes m_Type;
|
||||
|
||||
@@ -64,5 +64,21 @@ glm::mat4 Camera::GetTransformRotation()
|
||||
return lookAt(glm::vec3(), cameraFront, cameraUp);
|
||||
}
|
||||
|
||||
json Camera::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(m_Type);
|
||||
SERIALIZE_VAL(AspectRatio);
|
||||
SERIALIZE_VAL(Fov);
|
||||
SERIALIZE_VAL(Exposure);
|
||||
SERIALIZE_VAL(Speed);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool Camera::Deserialize(const std::string& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
#include "../Core/Timestep.h"
|
||||
#include <glm\vec3.hpp>
|
||||
#include <glm\ext\matrix_float4x4.hpp>
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
enum CAMERA_TYPE {
|
||||
ORTHO,
|
||||
PERSPECTIVE
|
||||
};
|
||||
class EditorCamera;
|
||||
class __declspec(dllexport) Camera
|
||||
class Camera : public ISerializable
|
||||
{
|
||||
private:
|
||||
CAMERA_TYPE m_Type;
|
||||
|
||||
float AspectRatio = 16.0f / 9.0f;
|
||||
|
||||
|
||||
glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 Scale = { 1.0f, 1.0f, 1.0f };
|
||||
|
||||
@@ -56,5 +57,8 @@ public:
|
||||
glm::mat4 GetTransform();
|
||||
glm::mat4 GetTransformRotation();
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const std::string& str) override;
|
||||
|
||||
friend EditorCamera;
|
||||
};
|
||||
|
||||
@@ -84,4 +84,21 @@ void ProceduralSky::Draw(Ref<Camera> cam) {
|
||||
|
||||
glm::vec3 ProceduralSky::GetSunDirection() {
|
||||
return SunDirection;
|
||||
}
|
||||
}
|
||||
|
||||
json ProceduralSky::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE()
|
||||
SERIALIZE_VAL(SurfaceRadius);
|
||||
SERIALIZE_VAL(AtmosphereRadius);
|
||||
SERIALIZE_VEC3(RayleighScattering);
|
||||
SERIALIZE_VEC3(MieScattering);
|
||||
SERIALIZE_VAL(SunIntensity);
|
||||
SERIALIZE_VEC3(SunDirection);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool ProceduralSky::Deserialize(const std::string& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include "Vertex.h"
|
||||
#include "../Core/Core.h"
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
class Camera;
|
||||
class ProceduralSky {
|
||||
class ProceduralSky : ISerializable {
|
||||
public:
|
||||
float SurfaceRadius = 6360e3;
|
||||
float AtmosphereRadius = 6380e3;
|
||||
glm::vec3 RayleighScattering = glm::vec3(58e-7, 135e-7, 331e-7);
|
||||
glm::vec3 MieScattering = glm::vec3(2e-5);
|
||||
float SunIntensity = 100.0;
|
||||
|
||||
glm::vec3 CenterPoint = glm::vec3(0, -SurfaceRadius, 0);
|
||||
glm::vec3 SunDirection = glm::vec3(0.20000, 0.95917, 0.20000);
|
||||
unsigned int VAO;
|
||||
@@ -19,4 +22,6 @@ public:
|
||||
|
||||
glm::vec3 GetSunDirection();
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const std::string& str) override;
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include "TransformComponent.h"
|
||||
#include "../Core/Core.h"
|
||||
class __declspec(dllexport) CameraComponent {
|
||||
#include "../Resource/Serializable.h"
|
||||
class CameraComponent {
|
||||
public:
|
||||
Ref<Camera> CameraInstance;
|
||||
TransformComponent* transformComponent;
|
||||
@@ -9,4 +10,11 @@ public:
|
||||
CameraComponent();
|
||||
|
||||
void DrawEditor();
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_OBJECT(CameraInstance);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "../Rendering/Camera.h"
|
||||
#include "../../../Rendering/Framebuffer.h"
|
||||
#include "BaseComponent.h";
|
||||
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
enum LightType {
|
||||
Directional, Point, Spot
|
||||
};
|
||||
|
||||
class __declspec(dllexport) LightComponent {
|
||||
class LightComponent {
|
||||
|
||||
public:
|
||||
glm::vec2 yes = glm::vec2(2, 2);
|
||||
@@ -201,4 +201,17 @@ public:
|
||||
|
||||
void SetType(LightType type);
|
||||
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Type);
|
||||
SERIALIZE_VEC3(Direction);
|
||||
SERIALIZE_VEC3(Color);
|
||||
SERIALIZE_VAL(IsVolumetric);
|
||||
SERIALIZE_VAL(Strength);
|
||||
SERIALIZE_VAL(SyncDirectionWithSky);
|
||||
SERIALIZE_VAL(CastShadows);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <glm\ext\matrix_float4x4.hpp>
|
||||
#include "BaseComponent.h";
|
||||
|
||||
class __declspec(dllexport) MeshComponent {
|
||||
class MeshComponent {
|
||||
|
||||
private:
|
||||
unsigned int VAO;
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
#pragma once
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
class NameComponent {
|
||||
public:
|
||||
std::string Name = "Entity";
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Name);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -2,10 +2,18 @@
|
||||
|
||||
#include "../Entity.h"
|
||||
|
||||
|
||||
struct ParentComponent
|
||||
{
|
||||
Entity Parent;
|
||||
bool HasParent = false;
|
||||
std::vector<Entity> Children = std::vector<Entity>();
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(HasParent);
|
||||
if(HasParent)
|
||||
SERIALIZE_VAL_LBL("Parent", Parent.GetHandle());
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -3,7 +3,9 @@
|
||||
#include <vector>
|
||||
#include "../Rendering/Mesh/Mesh.h"
|
||||
#include "../Resource/TrenchbroomMap.h"
|
||||
class __declspec(dllexport) QuakeMap {
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
class QuakeMap {
|
||||
private:
|
||||
|
||||
|
||||
@@ -18,4 +20,11 @@ public:
|
||||
void Draw();
|
||||
void DrawEditor();
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(HasCollisions);
|
||||
SERIALIZE_VAL(Path);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -32,7 +32,6 @@ float RigidBodyComponent::GetMass() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
void RigidBodyComponent::SetMass(float m)
|
||||
{
|
||||
if (!m_Rigidbody)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include <glm\ext\matrix_float4x4.hpp>
|
||||
#include "BaseComponent.h";
|
||||
class __declspec(dllexport) TransformComponent {
|
||||
#include "../Resource/Serializable.h"
|
||||
class TransformComponent {
|
||||
public:
|
||||
glm::vec3 Translation;
|
||||
glm::vec3 Rotation;
|
||||
@@ -11,4 +12,14 @@ public:
|
||||
glm::mat4 GetTransform();
|
||||
|
||||
void DrawEditor();
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL_LBL("Type", "TransformComponent");
|
||||
SERIALIZE_VEC3(Translation);
|
||||
SERIALIZE_VEC3(Rotation);
|
||||
SERIALIZE_VEC3(Scale);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
};
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#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"
|
||||
void Entity::AddChild(Entity ent)
|
||||
{
|
||||
if ((int)m_EntityHandle != ent.GetHandle())
|
||||
@@ -13,6 +18,26 @@ void Entity::AddChild(Entity ent)
|
||||
}
|
||||
}
|
||||
|
||||
json Entity::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_OBJECT_REF_LBL("NameComponent", GetComponent<NameComponent>());
|
||||
SERIALIZE_OBJECT_REF_LBL("ParentComponent", GetComponent<ParentComponent>());
|
||||
SERIALIZE_OBJECT_REF_LBL("TransformComponent", GetComponent<TransformComponent>());
|
||||
if(HasComponent<CameraComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent<CameraComponent>());
|
||||
if(HasComponent<QuakeMap>())
|
||||
SERIALIZE_OBJECT_REF_LBL("QuakemapComponent", GetComponent<QuakeMap>());
|
||||
if (HasComponent<LightComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("LightComponent", GetComponent<LightComponent>());
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool Entity::Deserialize(const std::string& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity::Entity(entt::entity handle, Scene* scene)
|
||||
{
|
||||
m_EntityHandle = handle;
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include <glm\ext\matrix_float4x4.hpp>
|
||||
#include "../Scene.h"
|
||||
#include "Components/BaseComponent.h"
|
||||
class __declspec(dllexport) Entity
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
class __declspec(dllexport) Entity : public ISerializable
|
||||
{
|
||||
public:
|
||||
Entity(entt::entity handle, Scene* scene);
|
||||
@@ -49,6 +51,10 @@ public:
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const std::string& str);
|
||||
|
||||
private:
|
||||
entt::entity m_EntityHandle;
|
||||
Scene* m_Scene;
|
||||
|
||||
@@ -24,4 +24,19 @@ void Environment::Push() {
|
||||
//Renderer::m_Shader->SetUniform4f("u_AmbientColor", 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
Renderer::m_Shader->SetUniform1f("u_FogAmount", VolumetricFog);
|
||||
Renderer::m_Shader->SetUniform1f("u_FogStepCount", VolumetricStepCount);
|
||||
}
|
||||
}
|
||||
|
||||
json Environment::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(VolumetricFog);
|
||||
SERIALIZE_VAL(VolumetricStepCount);
|
||||
SERIALIZE_VEC4(AmbientColor);
|
||||
SERIALIZE_OBJECT(ProceduralSkybox);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool Environment::Deserialize(const std::string& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include "../Core/Core.h"
|
||||
#include "../Rendering/ProceduralSky.h"
|
||||
|
||||
class __declspec(dllexport) Environment
|
||||
#include "../Resource/Serializable.h"
|
||||
class Environment : public ISerializable
|
||||
{
|
||||
public:
|
||||
Environment();
|
||||
@@ -15,10 +16,11 @@ public:
|
||||
Ref<ProceduralSky> ProceduralSkybox;
|
||||
|
||||
glm::vec4 m_AmbientColor;
|
||||
|
||||
glm::vec4 GetAmbientColor();
|
||||
|
||||
void SetAmbientColor(glm::vec4 color);
|
||||
|
||||
void Push();
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const std::string& str) override;
|
||||
};
|
||||
|
||||
@@ -9,29 +9,40 @@
|
||||
#include <GL/glew.h>
|
||||
#include "Entities/Components/BoxCollider.h"
|
||||
#include "../../Engine.h"
|
||||
#include "../Core/FileSystem.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
|
||||
Ref<Scene> Scene::New()
|
||||
{
|
||||
return CreateRef<Scene>();
|
||||
}
|
||||
|
||||
Scene::Scene()
|
||||
{
|
||||
m_Environement = CreateRef<Environment>();
|
||||
|
||||
auto camEntity = CreateEntity("Camera");
|
||||
camEntity.AddComponent<CameraComponent>().transformComponent = &camEntity.GetComponent<TransformComponent>();
|
||||
|
||||
m_EditorCamera = CreateRef<EditorCamera>();
|
||||
}
|
||||
|
||||
|
||||
Scene::~Scene() {
|
||||
}
|
||||
|
||||
|
||||
void Scene::Init() {
|
||||
//m_Skybox = new SkyboxHDR("Res/Textures/Skyboxes/HDR/lilienstein_4k.hdr");
|
||||
|
||||
m_Environement = CreateRef<Environment>();
|
||||
}
|
||||
|
||||
Scene::~Scene() {}
|
||||
|
||||
std::string Scene::GetName()
|
||||
{
|
||||
return this->Name;
|
||||
}
|
||||
|
||||
bool Scene::SetName(std::string& newName)
|
||||
{
|
||||
if (newName == "")
|
||||
return false;
|
||||
|
||||
this->Name = newName;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Scene::OnInit()
|
||||
{
|
||||
@@ -145,7 +156,6 @@ void Scene::Update(Timestep ts)
|
||||
void Scene::EditorUpdate(Timestep ts)
|
||||
{
|
||||
m_EditorCamera->Update(ts);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -206,72 +216,6 @@ void Scene::DrawShadows()
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::DrawGBuffer()
|
||||
{
|
||||
Renderer::m_GBufferShader->Bind();
|
||||
Ref<Camera> cam = nullptr;
|
||||
{
|
||||
auto view = m_Registry.view<TransformComponent, CameraComponent>();
|
||||
for (auto e : view) {
|
||||
auto [transform, camera] = view.get<TransformComponent, CameraComponent>(e);
|
||||
cam = camera.CameraInstance;
|
||||
cam->Translation = transform.Translation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cam)
|
||||
{
|
||||
auto view = m_Registry.view<TransformComponent, ModelComponent>();
|
||||
for (auto e : view) {
|
||||
auto [transform, model] = view.get<TransformComponent, ModelComponent>(e);
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_View", cam->GetTransform());
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_Projection", cam->GetPerspective());
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_Model", transform.GetTransform());
|
||||
model.Draw();
|
||||
}
|
||||
|
||||
auto view2 = m_Registry.view<TransformComponent, QuakeMap>();
|
||||
for (auto e : view2) {
|
||||
auto [transform, model] = view2.get<TransformComponent, QuakeMap>(e);
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_View", cam->GetTransform());
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_Projection", cam->GetPerspective());
|
||||
Renderer::m_GBufferShader->SetUniformMat4f("u_Model", transform.GetTransform());
|
||||
model.Draw();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::DrawDeferred()
|
||||
{
|
||||
// Find the camera of the scene.
|
||||
Ref<Camera> cam = nullptr;
|
||||
{
|
||||
auto view = m_Registry.view<TransformComponent, CameraComponent>();
|
||||
for (auto e : view) {
|
||||
auto [transform, camera] = view.get<TransformComponent, CameraComponent>(e);
|
||||
cam = camera.CameraInstance;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto view = m_Registry.view<TransformComponent, LightComponent>();
|
||||
for (auto l : view) {
|
||||
auto [transform, light] = view.get<TransformComponent, LightComponent>(l);
|
||||
//light.DrawDeferred(transform, cam);
|
||||
}
|
||||
}
|
||||
|
||||
//m_Skybox->Draw(cam->GetPerspective(), cam->GetTransform());
|
||||
if (m_Skybox != nullptr)
|
||||
m_Skybox->Push();
|
||||
glm::vec3 camPos = cam->GetTranslation();
|
||||
Renderer::m_DeferredShader->SetUniform1f("u_Exposure", cam->Exposure);
|
||||
Renderer::m_DeferredShader->SetUniform3f("u_EyePosition", camPos.x, camPos.y, camPos.z);
|
||||
Renderer::m_DeferredShader->SetUniformMat4f("u_View", cam->GetTransform());
|
||||
Renderer::m_DeferredShader->SetUniformMat4f("u_Projection", cam->GetPerspective());
|
||||
}
|
||||
|
||||
void Scene::Draw()
|
||||
{
|
||||
@@ -433,7 +377,6 @@ void Scene::EditorDraw()
|
||||
{
|
||||
currentParent = currentParent.GetComponent<ParentComponent>().Parent;
|
||||
globalOffset += currentParent.GetComponent<TransformComponent>().Translation;
|
||||
|
||||
}
|
||||
|
||||
copyT.Translation = globalOffset;
|
||||
@@ -589,7 +532,7 @@ glm::vec3 Scene::GetGlobalPosition(Entity ent)
|
||||
}
|
||||
|
||||
|
||||
Entity Scene::GetEntity(const std::string name)
|
||||
Entity Scene::GetEntity(const std::string& name)
|
||||
{
|
||||
std::vector<Entity> allEntities;
|
||||
auto view = m_Registry.view<TransformComponent, NameComponent>();
|
||||
@@ -600,7 +543,7 @@ Entity Scene::GetEntity(const std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
Entity Scene::CreateEntity(const std::string name) {
|
||||
Entity Scene::CreateEntity(const std::string& name) {
|
||||
Entity entity = { m_Registry.create(), this };
|
||||
|
||||
// Must have transform
|
||||
@@ -635,7 +578,6 @@ Ref<Camera> Scene::GetCurrentCamera()
|
||||
}
|
||||
}
|
||||
return cam;
|
||||
|
||||
}
|
||||
|
||||
return m_EditorCamera;
|
||||
@@ -644,3 +586,39 @@ Ref<Camera> Scene::GetCurrentCamera()
|
||||
Ref<Environment> Scene::GetEnvironment() {
|
||||
return m_Environement;
|
||||
}
|
||||
|
||||
bool Scene::Save()
|
||||
{
|
||||
if (Path == "")
|
||||
Path = FileDialog::SaveFile("*.scene") + ".scene";
|
||||
|
||||
return SaveAs(Path);
|
||||
}
|
||||
|
||||
bool Scene::SaveAs(const std::string& path)
|
||||
{
|
||||
std::ofstream sceneFile;
|
||||
sceneFile.open(path);
|
||||
sceneFile << Serialize().dump(4);
|
||||
sceneFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
json Scene::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Name);
|
||||
SERIALIZE_OBJECT(m_Environement)
|
||||
std::vector<json> entities = std::vector<json>();
|
||||
for (Entity e : GetAllEntities())
|
||||
entities.push_back(e.Serialize());
|
||||
SERIALIZE_VAL_LBL("Entities", entities);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Scene::Deserialize(const std::string& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
#include "../Rendering/ProceduralSky.h"
|
||||
#include "../Core/Core.h"
|
||||
#include "EditorCamera.h"
|
||||
#include "../Resource/Serializable.h"
|
||||
|
||||
class Entity;
|
||||
class __declspec(dllexport) Scene
|
||||
class Scene : public ISerializable
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
@@ -18,13 +19,17 @@ private:
|
||||
Ref<Environment> m_Environement;
|
||||
entt::registry m_Registry;
|
||||
Ref<EditorCamera> m_EditorCamera;
|
||||
|
||||
std::string Name;
|
||||
std::string Path = "";
|
||||
bool has_changed = true;
|
||||
public:
|
||||
|
||||
SkyboxHDR* m_Skybox;
|
||||
static Ref<Scene> New();
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
std::string GetName();
|
||||
bool SetName(std::string& newName);
|
||||
|
||||
void Init();
|
||||
void OnInit();
|
||||
void OnExit();
|
||||
@@ -39,10 +44,17 @@ public:
|
||||
|
||||
std::vector<Entity> GetAllEntities();
|
||||
glm::vec3 GetGlobalPosition(Entity ent);
|
||||
Entity GetEntity(const std::string name);
|
||||
Entity CreateEntity(const std::string name);
|
||||
Entity GetEntity(const std::string& name);
|
||||
Entity CreateEntity(const std::string& name);
|
||||
void DestroyEntity(Entity entity);
|
||||
|
||||
Ref<Camera> GetCurrentCamera();
|
||||
Ref<Environment> GetEnvironment();
|
||||
|
||||
bool Save();
|
||||
bool SaveAs(const std::string& path);
|
||||
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const std::string& str) override;
|
||||
};
|
||||
@@ -39,7 +39,7 @@ Window::Window()
|
||||
Init();
|
||||
Renderer::Init();
|
||||
|
||||
m_Scene->Init();
|
||||
//m_Scene->Init();
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
@@ -62,6 +62,12 @@ GLFWwindow* Window::GetHandle()
|
||||
return m_Window;
|
||||
}
|
||||
|
||||
bool Window::SetScene(Ref<Scene> scene)
|
||||
{
|
||||
m_Scene = scene;
|
||||
return true;
|
||||
}
|
||||
|
||||
Ref<Scene> Window::GetScene()
|
||||
{
|
||||
return m_Scene;
|
||||
@@ -205,7 +211,7 @@ int Window::Init()
|
||||
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
m_Scene = CreateRef<Scene>();
|
||||
//m_Scene = CreateRef<Scene>();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -224,163 +230,14 @@ bool init = false;
|
||||
|
||||
void Window::Draw()
|
||||
{
|
||||
Ref<Camera> cam = m_Scene->GetCurrentCamera();
|
||||
|
||||
if (!m_Scene)
|
||||
return;
|
||||
|
||||
Ref<Camera> cam = m_Scene->GetCurrentCamera();
|
||||
if (!cam)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
/*
|
||||
|
||||
static int selected = 0;
|
||||
{
|
||||
//QuadEntity* selectedEntity = m_Scene->GetEntity(selected);
|
||||
ImGui::Begin("Scene");
|
||||
{
|
||||
ImGui::BeginChild("Buttons", ImVec2(300, 20), false);
|
||||
if (ImGui::Button("Add")) {
|
||||
m_Scene->CreateEntity("Entity");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Remove"))
|
||||
{
|
||||
m_Scene->DestroyEntity(selectedEntity);
|
||||
selectedEntity = m_Scene->GetAllEntities().at(0);
|
||||
};
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
int idx = 0;
|
||||
for (Entity e : m_Scene->GetAllEntities()) {
|
||||
std::string name = e.GetComponent<NameComponent>().Name;
|
||||
if (ImGui::Selectable(name.c_str(), selected == idx)) {
|
||||
selected = idx;
|
||||
selectedEntity = e;
|
||||
}
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
// your popup code
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool show = true;
|
||||
int id = 0;
|
||||
|
||||
//
|
||||
//m_Scene->DrawShadows();
|
||||
//
|
||||
// Drawing to texture.
|
||||
|
||||
|
||||
|
||||
ImGui::Begin("ShadowMap");
|
||||
{
|
||||
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
if (selectedEntity.HasComponent<LightComponent>())
|
||||
ImGui::Image((void*)selectedEntity.GetComponent<LightComponent>().m_Framebuffer->GetTexture()->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//m_GBuffer->Bind();
|
||||
//m_Scene->DrawGBuffer();
|
||||
//m_GBuffer->Unbind();
|
||||
////
|
||||
//DrawQuad();
|
||||
|
||||
ImGui::Begin("Deferred output");
|
||||
{
|
||||
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
|
||||
ImGui::Image((void*)m_DeferredFrambuffer->GetTexture()->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
// Draw rect
|
||||
//Renderer::m_DeferredShader->Bind();
|
||||
|
||||
ImGui::Begin("depth");
|
||||
{
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
|
||||
ImGui::Image((void*)m_GBuffer->gDepth, regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::Begin("Albedo");
|
||||
{
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
// If viewport is resized
|
||||
if (m_GBuffer->GetSize() != viewportPanelSize)
|
||||
{
|
||||
// Update FBO size and camera aspect ratio.
|
||||
//m_Framebuffer->UpdateSize(viewportPanelSize);
|
||||
//cam->OnWindowResize(viewportPanelSize.x, viewportPanelSize.y);
|
||||
}
|
||||
|
||||
ImGui::Image((void*)m_GBuffer->gAlbedo, regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::Begin("Material");
|
||||
{
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
// If viewport is resized
|
||||
if (m_GBuffer->GetSize() != viewportPanelSize)
|
||||
{
|
||||
// Update FBO size and camera aspect ratio.
|
||||
//m_Framebuffer->UpdateSize(viewportPanelSize);
|
||||
//cam->OnWindowResize(viewportPanelSize.x, viewportPanelSize.y);
|
||||
}
|
||||
|
||||
ImGui::Image((void*)m_GBuffer->gMaterial, regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::Begin("Normal");
|
||||
{
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
|
||||
|
||||
// If viewport is resized
|
||||
if (m_GBuffer->GetSize() != viewportPanelSize)
|
||||
{
|
||||
// Update FBO size and camera aspect ratio.
|
||||
//m_Framebuffer->UpdateSize(viewportPanelSize);
|
||||
//cam->OnWindowResize(viewportPanelSize.x, viewportPanelSize.y);
|
||||
}
|
||||
|
||||
ImGui::Image((void*)m_GBuffer->gNormal, regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
||||
ImGui::End();
|
||||
}
|
||||
*/
|
||||
|
||||
Renderer::BeginDraw(cam);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
@@ -411,33 +268,33 @@ void Window::EndDraw()
|
||||
|
||||
void Window::DrawQuad()
|
||||
{
|
||||
Renderer::m_DeferredShader->Bind();
|
||||
//Renderer::m_DeferredShader->Bind();
|
||||
|
||||
m_DeferredFrambuffer->Bind();
|
||||
//m_DeferredFrambuffer->Bind();
|
||||
|
||||
m_Scene->DrawDeferred();
|
||||
//m_Scene->DrawDeferred();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 5);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GBuffer->gAlbedo);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 6);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GBuffer->gNormal);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 7);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GBuffer->gMaterial);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 8);
|
||||
glBindTexture(GL_TEXTURE_2D, m_GBuffer->gDepth);
|
||||
|
||||
Renderer::m_DeferredShader->SetUniform1i("m_Albedo", 5);
|
||||
Renderer::m_DeferredShader->SetUniform1i("m_Depth", 8);
|
||||
Renderer::m_DeferredShader->SetUniform1i("m_Normal", 6);
|
||||
Renderer::m_DeferredShader->SetUniform1i("m_Material", 7);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
m_DeferredFrambuffer->Unbind();
|
||||
//glActiveTexture(GL_TEXTURE0 + 5);
|
||||
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gAlbedo);
|
||||
//
|
||||
//glActiveTexture(GL_TEXTURE0 + 6);
|
||||
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gNormal);
|
||||
//
|
||||
//glActiveTexture(GL_TEXTURE0 + 7);
|
||||
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gMaterial);
|
||||
//
|
||||
//glActiveTexture(GL_TEXTURE0 + 8);
|
||||
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gDepth);
|
||||
//
|
||||
//Renderer::m_DeferredShader->SetUniform1i("m_Albedo", 5);
|
||||
//Renderer::m_DeferredShader->SetUniform1i("m_Depth", 8);
|
||||
//Renderer::m_DeferredShader->SetUniform1i("m_Normal", 6);
|
||||
//Renderer::m_DeferredShader->SetUniform1i("m_Material", 7);
|
||||
//
|
||||
//glBindVertexArray(vao);
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
//
|
||||
//m_DeferredFrambuffer->Unbind();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
static Window* Get();
|
||||
GLFWwindow* GetHandle();
|
||||
|
||||
|
||||
|
||||
int Init();
|
||||
void Update(Timestep ts);
|
||||
void Draw();
|
||||
@@ -33,5 +35,7 @@ public:
|
||||
|
||||
void DrawQuad();
|
||||
Ref<Scene> GetScene();
|
||||
bool SetScene(Ref<Scene> scene);
|
||||
|
||||
Ref<FrameBuffer> GetFrameBuffer() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user