Serialization of bsp hulls and deserialization

This commit is contained in:
antopilo
2023-03-14 23:16:50 -04:00
parent ca7b8955bf
commit 2611c3f6c2
2 changed files with 29 additions and 2 deletions

View File

@@ -35,9 +35,18 @@ namespace Nuake {
{
BEGIN_SERIALIZE();
for (uint32_t i = 0; i < Meshes.size(); i++)
for (uint32_t i = 0; i < Hulls.size() - 1; i++)
{
j["Meshes"][i] = Meshes[i]->Serialize();
json hullPointsJson;
const size_t hullSize = Hulls[i].size() - 1;
for (uint32_t j = 0; j < hullSize; j++)
{
hullPointsJson[j]["x"] = Hulls[i][j].x;
hullPointsJson[j]["y"] = Hulls[i][j].y;
hullPointsJson[j]["z"] = Hulls[i][j].z;
}
j["Hulls"][i] = hullPointsJson;
}
j["IsSolid"] = IsSolid;
@@ -53,6 +62,23 @@ namespace Nuake {
IsSolid = j["IsSolid"];
}
if (j.contains("Hulls"))
{
for (auto& h : j["Hulls"])
{
std::vector<Vector3> hull;
hull.reserve(h.size());
for (auto& point : h)
{
Vector3 pointPos;
DESERIALIZE_VEC3(point, pointPos);
hull.push_back(std::move(pointPos));
}
Hulls.push_back(hull);
}
}
return true;
}
};

View File

@@ -83,6 +83,7 @@ namespace Nuake
DESERIALIZE_COMPONENT(MeshColliderComponent);
DESERIALIZE_COMPONENT(SphereColliderComponent);
DESERIALIZE_COMPONENT(RigidBodyComponent);
DESERIALIZE_COMPONENT(BSPBrushComponent);
return true;
}