Skip to content

Commit

Permalink
Added layout
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 15, 2024
1 parent 4bce64b commit 9b2a174
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SOURCES "src/engine.cpp" "include/Components/CloudComponent.h" "src/Components/CloudComponent.cpp" ../GUI/src/MeshInfo.cpp ../GUI/include/MeshInfo.h src/Containers/VAO.cpp include/Containers/VAO.h src/Containers/VBO.cpp include/Containers/VBO.h src/Containers/EBO.cpp include/Containers/EBO.h ../GUI/src/ImGuiTabs.cpp ../GUI/include/ImGuiTabs.h src/Pipelines/PipelineSSR.cpp include/Pipelines/PipelineSSR.h src/Components/Component.cpp include/Components/Component.h src/Components/PhysicsMeshComponent.cpp include/Components/PhysicsMeshComponent.h src/Handlers/ComponentsHandler.cpp include/Handlers/ComponentsHandler.h ../GUI/src/FolderView.cpp ../GUI/include/FolderView.h)

add_library(PrismaEngineDll STATIC ${SOURCES} "include/SceneObjects/Node.h" "src/SceneObjects/Node.cpp" "include/SceneData/SceneExporterLayout.h" "include/Helpers/Shader.h" "include/SceneData/SceneExporter.h" "src/SceneData/SceneExporter.cpp" "include/Helpers/Shader.h" "include/Helpers/stb_image.h" "include/SceneData/SceneLoader.h" "src/SceneData/SceneLoader.cpp" "include/Containers/Texture.h" "src/Containers/Texture.cpp" "include/SceneObjects/Camera.h" "src/SceneObjects/Camera.cpp" "include/SceneObjects/Mesh.h" "src/SceneObjects/Mesh.cpp" "include/Pipelines/PipelineForward.h" "src/Pipelines/PipelineForward.cpp" "include/Helpers/Settings.h" "include/Components/MaterialComponent.h" "src/Components/MaterialComponent.cpp" "include/SceneObjects/Light.h" "../GUI/include/ImGuiDebug.h" "../GUI/src/ImguiDebug.cpp" "../GUI/include/SettingsTab.h" "../GUI/src/SettingsTab.cpp" "../GUI/include/ImGuiCamera.h" "../GUI/src/ImguiCamera.cpp" "include/Containers/Ubo.h" "include/GlobalData/Defines.h" "include/Handlers/LightHandler.h" "src/Handlers/LightHandler.cpp" "include/Helpers/NodeHelper.h" "src/Helpers/NodeHelper.cpp" "include/SceneData/SceneData.h" "include/Helpers/ScenePrinter.h" "src/Helpers/ScenePrinter.cpp" "include/Containers/SSBO.h" "include/Handlers/MeshHandler.h" "src/Handlers/MeshHandler.cpp" "include/GlobalData/PrismaFunc.h" "src/GlobalData/PrismaFunc.cpp" "include/SceneData/MeshIndirect.h" "src/SceneData/MeshIndirect.cpp" "include/Containers/FBO.h" "src/Containers/FBO.cpp" "include/Pipelines/PipelineFullScreen.h" "src/Pipelines/PipelineFullScreen.cpp" "include/Pipelines/PipelineDeferred.h" "src/Pipelines/PipelineDeferred.cpp" "include/GlobalData/GlobalData.h" "include/GlobalData/Keys.h" "src/Containers/SSBO.cpp" "src/Containers/UBO.cpp" "include/Pipelines/PipelineHandler.h" "src/Pipelines/PipelineHandler.cpp" "include/Helpers/SettingsLoader.h" "src/Helpers/SettingsLoader.cpp" "include/Pipelines/PipelineSkybox.h" "src/Pipelines/PipelineSkybox.cpp" "src/GlobalData/GlobalData.cpp" "include/Pipelines/PipelineDIffuseIrradiance.h" "src/Pipelines/PipelineDiffuseIrradiance.cpp" "include/Pipelines/PipelinePrefilter.h" "src/Pipelines/PipelinePrefilter.cpp" "include/Pipelines/PipelineLUT.h" "src/Pipelines/PipelineLUT.cpp" "include/Pipelines/PipelineOmniShadow.h" "src/Pipelines/PipelineOmniShadow.cpp" "include/Helpers/PrismaRender.h" "src/Helpers/PrismaRender.cpp" "include/Pipelines/GenericShadow.h" "include/Physics/Physics.h" "src/Physics/Physics.cpp" "include/Physics/Line.h" "src/Physics/Line.cpp" "include/Physics/DrawDebugger.h" "src/Physics/DrawDebugger.cpp" "include/Helpers/GarbageCollector.h" "src/Helpers/GarbageCollector.cpp" "include/Helpers/PrismaMath.h" "include/Postprocess/Postprocess.h" "src/Postprocess/Postprocess.cpp" "include/Postprocess/PostprocessEffect.h" "src/Postprocess/PostprocessEffect.cpp" "include/Pipelines/PipelineCSM.h" "src/Pipelines/PipelineCSM.cpp" "include/Helpers/ClusterCalculation.h" "src/Helpers/ClusterCalculation.cpp" "include/Helpers/TimeCounter.h" "include/SceneData/Animator.h" "src/SceneData/Animator.cpp" "include/SceneData/Animation.h" "src/SceneData/Animation.cpp" "include/SceneObjects/AnimatedMesh.h" "src/SceneObjects/AnimatedMesh.cpp" "include/SceneData/Bone.h" "src/SceneData/Bone.cpp" "include/Handlers/AnimationHandler.h" "src/Handlers/AnimationHandler.cpp" "include/GlobalData/CacheScene.h" "src/GlobalData/CacheScene.cpp" "include/Pipelines/PipelinePrePass.h" "src/Pipelines/PipelinePrePass.cpp" "include/GlobalData/EngineSettings.h" "include/Pipelines/PipelineSSAO.h" "src/Pipelines/PipelineSSAO.cpp" "include/SceneObjects/Sprite.h" "src/SceneObjects/Sprite.cpp" "../UserEngine/Components/include/TerrainComponent.h" "../UserEngine/Components/src/TerrainComponent.cpp" "include/Components/CullingComponent.h" "src/Components/CullingComponent.cpp" "src/Helpers/TimeCounter.cpp" "include/Helpers/Shadinclude.h" "include/Physics/PhysicsData.h" "include/Pipelines/PipelineDeferredForward.h" "src/Pipelines/PipelineDeferredForward.cpp")
add_library(PrismaEngineDll STATIC ${SOURCES} "include/SceneObjects/Node.h" "src/SceneObjects/Node.cpp" "include/SceneData/SceneExporterLayout.h" "include/Helpers/Shader.h" "include/SceneData/SceneExporter.h" "src/SceneData/SceneExporter.cpp" "include/Helpers/Shader.h" "include/Helpers/stb_image.h" "include/SceneData/SceneLoader.h" "src/SceneData/SceneLoader.cpp" "include/Containers/Texture.h" "src/Containers/Texture.cpp" "include/SceneObjects/Camera.h" "src/SceneObjects/Camera.cpp" "include/SceneObjects/Mesh.h" "src/SceneObjects/Mesh.cpp" "include/Pipelines/PipelineForward.h" "src/Pipelines/PipelineForward.cpp" "include/Helpers/Settings.h" "include/Components/MaterialComponent.h" "src/Components/MaterialComponent.cpp" "include/SceneObjects/Light.h" "../GUI/include/ImGuiDebug.h" "../GUI/src/ImguiDebug.cpp" "../GUI/include/SettingsTab.h" "../GUI/src/SettingsTab.cpp" "../GUI/include/ImGuiCamera.h" "../GUI/src/ImguiCamera.cpp" "include/Containers/Ubo.h" "include/GlobalData/Defines.h" "include/Handlers/LightHandler.h" "src/Handlers/LightHandler.cpp" "include/Helpers/NodeHelper.h" "src/Helpers/NodeHelper.cpp" "include/SceneData/SceneData.h" "include/Helpers/ScenePrinter.h" "src/Helpers/ScenePrinter.cpp" "include/Containers/SSBO.h" "include/Handlers/MeshHandler.h" "src/Handlers/MeshHandler.cpp" "include/GlobalData/PrismaFunc.h" "src/GlobalData/PrismaFunc.cpp" "include/SceneData/MeshIndirect.h" "src/SceneData/MeshIndirect.cpp" "include/Containers/FBO.h" "src/Containers/FBO.cpp" "include/Pipelines/PipelineFullScreen.h" "src/Pipelines/PipelineFullScreen.cpp" "include/Pipelines/PipelineDeferred.h" "src/Pipelines/PipelineDeferred.cpp" "include/GlobalData/GlobalData.h" "include/GlobalData/Keys.h" "src/Containers/SSBO.cpp" "src/Containers/UBO.cpp" "include/Pipelines/PipelineHandler.h" "src/Pipelines/PipelineHandler.cpp" "include/Helpers/SettingsLoader.h" "src/Helpers/SettingsLoader.cpp" "include/Pipelines/PipelineSkybox.h" "src/Pipelines/PipelineSkybox.cpp" "src/GlobalData/GlobalData.cpp" "include/Pipelines/PipelineDIffuseIrradiance.h" "src/Pipelines/PipelineDiffuseIrradiance.cpp" "include/Pipelines/PipelinePrefilter.h" "src/Pipelines/PipelinePrefilter.cpp" "include/Pipelines/PipelineLUT.h" "src/Pipelines/PipelineLUT.cpp" "include/Pipelines/PipelineOmniShadow.h" "src/Pipelines/PipelineOmniShadow.cpp" "include/Helpers/PrismaRender.h" "src/Helpers/PrismaRender.cpp" "include/Pipelines/GenericShadow.h" "include/Physics/Physics.h" "src/Physics/Physics.cpp" "include/Physics/Line.h" "src/Physics/Line.cpp" "include/Physics/DrawDebugger.h" "src/Physics/DrawDebugger.cpp" "include/Helpers/GarbageCollector.h" "src/Helpers/GarbageCollector.cpp" "include/Helpers/PrismaMath.h" "include/Postprocess/Postprocess.h" "src/Postprocess/Postprocess.cpp" "include/Postprocess/PostprocessEffect.h" "src/Postprocess/PostprocessEffect.cpp" "include/Pipelines/PipelineCSM.h" "src/Pipelines/PipelineCSM.cpp" "include/Helpers/ClusterCalculation.h" "src/Helpers/ClusterCalculation.cpp" "include/Helpers/TimeCounter.h" "include/SceneData/Animator.h" "src/SceneData/Animator.cpp" "include/SceneData/Animation.h" "src/SceneData/Animation.cpp" "include/SceneObjects/AnimatedMesh.h" "src/SceneObjects/AnimatedMesh.cpp" "include/SceneData/Bone.h" "src/SceneData/Bone.cpp" "include/Handlers/AnimationHandler.h" "src/Handlers/AnimationHandler.cpp" "include/GlobalData/CacheScene.h" "src/GlobalData/CacheScene.cpp" "include/Pipelines/PipelinePrePass.h" "src/Pipelines/PipelinePrePass.cpp" "include/GlobalData/EngineSettings.h" "include/Pipelines/PipelineSSAO.h" "src/Pipelines/PipelineSSAO.cpp" "include/SceneObjects/Sprite.h" "src/SceneObjects/Sprite.cpp" "../UserEngine/Components/include/TerrainComponent.h" "../UserEngine/Components/src/TerrainComponent.cpp" "include/Components/CullingComponent.h" "src/Components/CullingComponent.cpp" "src/Helpers/TimeCounter.cpp" "include/Helpers/Shadinclude.h" "include/Physics/PhysicsData.h" "include/Pipelines/PipelineDeferredForward.h" "src/Pipelines/PipelineDeferredForward.cpp" "include/SceneData/ComponentTypeLayout.h")

target_include_directories(PrismaEngineDll PUBLIC ${JoltPhysics_SOURCE_DIR}/..)

Expand Down
5 changes: 5 additions & 0 deletions Engine/include/Components/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <tuple>
#include "../SceneObjects/Node.h"
#include "../Containers/FBO.h"
#include <nlohmann/json.hpp>

namespace Prisma
{
Expand Down Expand Up @@ -74,6 +75,10 @@ namespace Prisma

Component();

virtual nlohmann::json& serialize();

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

virtual ~Component();

void uiRemovable(bool uiRemovable);
Expand Down
6 changes: 6 additions & 0 deletions Engine/include/Components/PhysicsMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ namespace Prisma

Body* softId();

nlohmann::json& serialize() override;

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

private:
ComponentList m_status;
std::function<void()> m_apply;
Expand All @@ -92,6 +96,8 @@ namespace Prisma
std::shared_ptr<BodyID> m_physicsId = nullptr;
Body* m_physicsSoftId = nullptr;

nlohmann::json m_jsonComponent;


Physics::LandscapeData m_landscapeData;

Expand Down
105 changes: 105 additions & 0 deletions Engine/include/SceneData/ComponentTypeLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma once
#include <nlohmann/json.hpp>
#include "../Physics/Physics.h"


namespace Prisma
{
using json = nlohmann::json;


// Conversion functions to/from JSON for Collider enum
NLOHMANN_JSON_SERIALIZE_ENUM(Prisma::Physics::Collider, {
{Prisma::Physics::Collider::BOX_COLLIDER, "BOX_COLLIDER"},
{Prisma::Physics::Collider::SPHERE_COLLIDER, "SPHERE_COLLIDER"},
{Prisma::Physics::Collider::LANDSCAPE_COLLIDER, "LANDSCAPE_COLLIDER"},
{Prisma::Physics::Collider::CONVEX_COLLIDER, "CONVEX_COLLIDER"}
})

// Conversion functions to/from JSON for CollisionData
void to_json(json& j, const Prisma::Physics::CollisionData& data)
{
j = json{
{"collider", data.collider},
{"mass", data.mass},
{"dynamic", data.dynamic},
{"softBody", data.softBody},
{"friction", data.friction},
{"restitution", data.restitution},
{"pressure", data.pressure}
};
}

void from_json(const json& j, Prisma::Physics::CollisionData& data)
{
j.at("collider").get_to(data.collider);
j.at("mass").get_to(data.mass);
j.at("dynamic").get_to(data.dynamic);
j.at("softBody").get_to(data.softBody);
j.at("friction").get_to(data.friction);
j.at("restitution").get_to(data.restitution);
j.at("pressure").get_to(data.pressure);
}

// Conversion functions to/from JSON for SoftBodySettings
void to_json(json& j, const Prisma::Physics::SoftBodySettings& settings)
{
j = json{
{"numIteration", settings.numIteration},
{"sleep", settings.sleep},
{"updatePosition", settings.updatePosition},
{
"vertexAttributes", {
{"attribute1", settings.vertexAttributes.mBendCompliance},
{"attribute2", settings.vertexAttributes.mCompliance},
{"attribute3", settings.vertexAttributes.mShearCompliance}
}
}
};
}

void from_json(const json& j, Prisma::Physics::SoftBodySettings& settings)
{
j.at("numIteration").get_to(settings.numIteration);
j.at("sleep").get_to(settings.sleep);
j.at("updatePosition").get_to(settings.updatePosition);
j.at("vertexAttributes").at("attribute1").get_to(settings.vertexAttributes.mBendCompliance);
j.at("vertexAttributes").at("attribute2").get_to(settings.vertexAttributes.mCompliance);
j.at("vertexAttributes").at("attribute3").get_to(settings.vertexAttributes.mShearCompliance);
}

// Conversion functions to/from JSON for LandscapeData
void to_json(json& j, const Prisma::Physics::LandscapeData& data)
{
std::vector<float> landscapeData;
for (auto landscape : data.landscape)
{
landscapeData.push_back(landscape);
}
j = json{
{"landscape", landscapeData},
{"offset", {data.offset.GetX(), data.offset.GetY(), data.offset.GetZ()}},
{"scale", {data.scale.GetX(), data.scale.GetY(), data.scale.GetZ()}},
{"width", data.width}
};
}

void from_json(const json& j, Prisma::Physics::LandscapeData& data)
{
std::vector<float> landscapeData;
j.at("landscape").get_to(landscapeData);
for (auto landscape : landscapeData)
{
data.landscape.push_back(landscape);
}
auto offset = j.at("offset");
data.offset.SetX(offset[0]);
data.offset.SetY(offset[1]);
data.offset.SetZ(offset[2]);
auto scale = j.at("scale");
data.scale.SetX(scale[0]);
data.scale.SetY(scale[1]);
data.scale.SetZ(scale[2]);
j.at("width").get_to(data.width);
}
}
9 changes: 9 additions & 0 deletions Engine/src/Components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ Prisma::Component::Component()
Prisma::GlobalData::getInstance().sceneComponents()[m_uuid] = this;
}

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

void Prisma::Component::deserialize(nlohmann::json& data)
{
}


Prisma::Component::~Component()
{
Expand Down
16 changes: 16 additions & 0 deletions Engine/src/Components/PhysicsMeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../include/SceneData/MeshIndirect.h"
#include "Jolt/Physics/Collision/Shape/ConvexHullShape.h"
#include "Jolt/Physics/SoftBody/SoftBodyCreationSettings.h"
#include "../../include/SceneData/ComponentTypeLayout.h"

void Prisma::PhysicsMeshComponent::ui()
{
Expand Down Expand Up @@ -213,6 +214,21 @@ Body* Prisma::PhysicsMeshComponent::softId()
return m_physicsSoftId;
}

nlohmann::json& Prisma::PhysicsMeshComponent::serialize()
{
m_jsonComponent = {
{"CollisionData", m_collisionData},
{"LandscapeData", m_landscapeData},
{"SoftBodySettings", m_settingsSoft}
};
return m_jsonComponent;
}

void Prisma::PhysicsMeshComponent::deserialize(nlohmann::json& data)
{
Component::deserialize(data);
}

BodyCreationSettings Prisma::PhysicsMeshComponent::getBodySettings()
{
auto mesh = dynamic_cast<Mesh*>(parent());
Expand Down

0 comments on commit 9b2a174

Please sign in to comment.