Skip to content

Commit

Permalink
Added groups
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 15, 2024
1 parent 9b2a174 commit f73c990
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 33 deletions.
48 changes: 23 additions & 25 deletions Engine/include/Components/CloudComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@ namespace Prisma

void start() override;

private:
unsigned int m_modelPos;

unsigned int m_lightPos;

unsigned int m_timePos;

unsigned int m_noisePos;

unsigned int m_invViewPos;
unsigned int m_invProjPos;
unsigned int m_camPos;

unsigned int m_perlworlPos;
unsigned int m_worlPos;

unsigned int m_upscalePos;
unsigned int m_resUpscalePos;
unsigned int m_factorPos;

GLuint m_downscalesq = 4 * 4;

std::shared_ptr<SSBO> m_ssbo;

struct alignas(16) CloudSSBO
{
// Cloud model
Expand Down Expand Up @@ -103,6 +79,29 @@ namespace Prisma
glm::vec2 padding5;
};

private:
unsigned int m_modelPos;

unsigned int m_lightPos;

unsigned int m_timePos;

unsigned int m_noisePos;

unsigned int m_invViewPos;
unsigned int m_invProjPos;
unsigned int m_camPos;

unsigned int m_perlworlPos;
unsigned int m_worlPos;

unsigned int m_upscalePos;
unsigned int m_resUpscalePos;
unsigned int m_factorPos;

GLuint m_downscalesq = 4 * 4;

std::shared_ptr<SSBO> m_ssbo;
CloudSSBO m_cloudSSBO;

std::chrono::system_clock::time_point m_start;
Expand All @@ -125,7 +124,6 @@ namespace Prisma

void setVariables();

private:
const int m_downscale = 4;

std::function<void()> m_startButton;
Expand Down
2 changes: 1 addition & 1 deletion Engine/include/Components/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Prisma

Component();

virtual nlohmann::json& serialize();
virtual nlohmann::json serialize();

virtual void deserialize(nlohmann::json& data);

Expand Down
2 changes: 1 addition & 1 deletion Engine/include/Components/PhysicsMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Prisma

Body* softId();

nlohmann::json& serialize() override;
nlohmann::json serialize() override;

void deserialize(nlohmann::json& data) override;

Expand Down
2 changes: 2 additions & 0 deletions Engine/include/Handlers/ComponentsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../GlobalData/GlobalData.h"
#include "../Components/Component.h"
#include "../GlobalData/InstanceData.h"
#include "../Components/RegisterCreator.h"


namespace Prisma
Expand Down Expand Up @@ -30,5 +31,6 @@ namespace Prisma

private:
std::vector<std::shared_ptr<Component>> m_components;
Prisma::RegisterData m_registerData;
};
}
7 changes: 7 additions & 0 deletions Engine/include/SceneData/ComponentTypeLayout.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <nlohmann/json.hpp>
#include "../Physics/Physics.h"
#include "../Components/CloudComponent.h"


namespace Prisma
Expand Down Expand Up @@ -102,4 +103,10 @@ namespace Prisma
data.scale.SetZ(scale[2]);
j.at("width").get_to(data.width);
}

// Serialization for glm::vec3
void to_json(json& j, const glm::vec3& vec)
{
j = json{vec.x, vec.y, vec.z};
}
}
28 changes: 28 additions & 0 deletions Engine/include/SceneData/SceneExporterLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include "../Components/RegisterComponent.h"
#include "../SceneObjects/Node.h"
#include "../SceneObjects/AnimatedMesh.h"
#include "../SceneObjects/Light.h"
Expand Down Expand Up @@ -289,6 +291,15 @@ namespace Prisma
};
j["farPlane"] = light->type().farPlane.x;
}

std::vector<std::pair<std::string, json>> componentJson;

for (auto& [name, component] : n->components())
{
componentJson.push_back({name, component->serialize()});
}

j["components"] = componentJson;
}

// Deserialize NodeExport from JSON
Expand Down Expand Up @@ -632,5 +643,22 @@ namespace Prisma

mesh->loadAnimateModel(verticesData);
}
if (!j.contains("components") || !j["components"].is_array())
return;

for (const auto& componentData : j["components"])
{
std::string componentName = componentData[0];
if (!name.empty())
{
json componentJson = componentData[1];
auto component = Prisma::Factory::createInstance(componentName);
if (component)
{
component->deserialize(componentJson);
n->addComponent(component);
}
}
}
}
}
4 changes: 2 additions & 2 deletions Engine/src/Components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Prisma::Component::Component()
Prisma::GlobalData::getInstance().sceneComponents()[m_uuid] = this;
}

nlohmann::json& Prisma::Component::serialize()
nlohmann::json Prisma::Component::serialize()
{
return std::move(nlohmann::json());
return nlohmann::json();
}

void Prisma::Component::deserialize(nlohmann::json& data)
Expand Down
12 changes: 10 additions & 2 deletions Engine/src/Components/PhysicsMeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Body* Prisma::PhysicsMeshComponent::softId()
return m_physicsSoftId;
}

nlohmann::json& Prisma::PhysicsMeshComponent::serialize()
nlohmann::json Prisma::PhysicsMeshComponent::serialize()
{
m_jsonComponent = {
{"CollisionData", m_collisionData},
Expand All @@ -226,7 +226,15 @@ nlohmann::json& Prisma::PhysicsMeshComponent::serialize()

void Prisma::PhysicsMeshComponent::deserialize(nlohmann::json& data)
{
Component::deserialize(data);
// Validate input JSON and populate member variables
if (data.contains("CollisionData") && data["CollisionData"].is_object())
data.at("CollisionData").get_to(m_collisionData);

if (data.contains("LandscapeData") && data["LandscapeData"].is_object())
data.at("LandscapeData").get_to(m_landscapeData);

if (data.contains("SoftBodySettings") && data["SoftBodySettings"].is_object())
data.at("SoftBodySettings").get_to(m_settingsSoft);
}

BodyCreationSettings Prisma::PhysicsMeshComponent::getBodySettings()
Expand Down
1 change: 1 addition & 0 deletions Engine/src/Handlers/ComponentsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ void Prisma::ComponentsHandler::removeComponent(std::shared_ptr<Component> compo

Prisma::ComponentsHandler::ComponentsHandler()
{
m_registerData.init();
}
1 change: 0 additions & 1 deletion GUI/include/ImGuiDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,5 @@ namespace Prisma
TimeCounter m_timeCounterEngine;

Prisma::ImGuiAddingMenu m_addingMenu;
Prisma::RegisterData m_registerData;
};
}
1 change: 0 additions & 1 deletion GUI/src/ImguiDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ Prisma::ImguiDebug::ImguiDebug() : m_lastFrameTime{glfwGetTime()}, m_fps{60.0f}
m_pauseButton->loadTexture({"../../../GUI/icons/pause.png", false, false, false});

NodeViewer::getInstance();
m_registerData.init();

initStatus();
}
Expand Down
Binary file modified Resources/DefaultScene/default.prisma
Binary file not shown.

0 comments on commit f73c990

Please sign in to comment.