-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
denis
authored and
denis
committed
Nov 15, 2024
1 parent
4bce64b
commit 9b2a174
Showing
6 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters