Skip to content

Commit

Permalink
serializing terrain
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumanvienna committed Jun 9, 2024
1 parent bf8a2f9 commit 3e16038
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion application/lucre/UI/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "vendor/imgui/imgui.h"
#include "vendor/imGuizmo/ImGuizmo.h"
#include "scene/sceneLoader.h"
#include "renderer/gltf.h"
#include "scene/gltf.h"

namespace LucreApp
{
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/builder/fastgltfBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <fastgltf/glm_element_traits.hpp>

#include "renderer/model.h"
#include "renderer/gltf.h"
#include "scene/gltf.h"
#include "scene/scene.h"

namespace GfxRenderEngine
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/builder/fbxBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "assimp/scene.h"

#include "renderer/model.h"
#include "renderer/fbx.h"
#include "scene/fbx.h"
#include "scene/scene.h"

namespace GfxRenderEngine
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/builder/gltfBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include "renderer/model.h"
#include "renderer/gltf.h"
#include "scene/gltf.h"
#include "scene/scene.h"

namespace GfxRenderEngine
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/builder/ufbxBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "ufbx/ufbx.h"

#include "renderer/model.h"
#include "renderer/fbx.h"
#include "scene/fbx.h"
#include "scene/scene.h"

namespace GfxRenderEngine
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion engine/scene/sceneLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <unordered_map>

#include "engine.h"
#include "renderer/gltf.h"
#include "scene/gltf.h"
#include "scene/scene.h"
#include "yaml-cpp/yaml.h"

Expand Down
13 changes: 10 additions & 3 deletions engine/scene/sceneLoaderJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
using namespace simdjson;

#include "engine.h"
#include "renderer/fbx.h"
#include "renderer/gltf.h"
#include "renderer/obj.h"
#include "scene/scene.h"
#include "scene/fbx.h"
#include "scene/gltf.h"
#include "scene/obj.h"
#include "scene/terrain.h"

namespace GfxRenderEngine
Expand Down Expand Up @@ -88,11 +88,13 @@ namespace GfxRenderEngine
void SerializeString(int indent, std::string const& key, std::string const& value, bool noComma = false);
void SerializeBool(int indent, std::string const& key, bool value, bool noComma = false);
void SerializeNumber(int indent, std::string const& key, double const value, bool noComma = false);

void SerializeGltfFiles(int indent, bool noComma);
void SerializeFastgltfFiles(int indent, bool noComma);
void SerializeGltfFile(int indent, Gltf::GltfFile const& gltfFile, bool noComma);
void SerializeInstances(int indent, std::vector<Gltf::Instance> const& instances);
void SerializeInstance(int indent, Gltf::Instance const& instance, bool noComma);

void SerializeTransform(int indent, entt::entity const& entity, bool noComma = false);
void SerializeNodes(int indent, std::vector<Gltf::Node> const& nodes);
void SerializeNode(int indent, Gltf::Node const& node, bool noComma);
Expand All @@ -109,6 +111,11 @@ namespace GfxRenderEngine
void SerializeInstances(int indent, std::vector<Obj::Instance> const& instances);
void SerializeInstance(int indent, Obj::Instance const& instance, bool noComma);

void SerializeTerrrainDescriptions(int indent, bool noComma);
void SerializeTerrrainDescription(int indent, Terrain::TerrainDescription const& terrainDescription, bool noComma);
void SerializeInstances(int indent, std::vector<Terrain::Instance> const& instances);
void SerializeInstance(int indent, Terrain::Instance const& instance, bool noComma);

private:
std::ofstream m_OutputFile;
static constexpr double SUPPORTED_FILE_FORMAT_VERSION = 1.2;
Expand Down
60 changes: 60 additions & 0 deletions engine/scene/sceneLoaderSerializeJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ namespace GfxRenderEngine
SerializeString(indent, "description", m_SceneDescriptionFile.m_Description);
SerializeString(indent, "author", m_SceneDescriptionFile.m_Author);

if (fastgltfFileCount) // terrain
{
bool noComma = (fastgltfFileCount == 0) && (gltfFileCount == 0) && (fbxFileCount == 0) && (ufbxFileCount == 0) &&
(objFileCount == 0);
SerializeTerrrainDescriptions(indent, noComma);
}
if (fastgltfFileCount) // fastgltf
{
bool noComma = (gltfFileCount == 0) && (fbxFileCount == 0) && (ufbxFileCount == 0) && (objFileCount == 0);
Expand Down Expand Up @@ -357,4 +363,58 @@ namespace GfxRenderEngine
m_OutputFile << indentStr << "}" << (noComma ? "" : ",") << "\n";
}

void SceneLoaderJSON::SerializeTerrrainDescriptions(int indent, bool noComma)
{
std::string indentStr(indent, ' ');
m_OutputFile << indentStr << "\"terrain\":\n";
m_OutputFile << indentStr << "[\n";
indent += 4;
size_t terrainDescriptionCount = m_SceneDescriptionFile.m_TerrainDescriptions.size();
size_t terrainDescriptionIndex = 0;
for (auto& terrainDescription : m_SceneDescriptionFile.m_TerrainDescriptions)
{
bool noCommaLocal = ((terrainDescriptionIndex + 1) == terrainDescriptionCount);
SerializeTerrrainDescription(indent, terrainDescription, noCommaLocal);
++terrainDescriptionIndex;
}
m_OutputFile << indentStr << "]" << (noComma ? "" : ",") << "\n";
}

void SceneLoaderJSON::SerializeTerrrainDescription(int indent, Terrain::TerrainDescription const& terrainDescription,
bool noComma)
{
std::string indentStr(indent, ' ');
m_OutputFile << indentStr << "{\n";
indent += 4;
SerializeString(indent, "filename", terrainDescription.m_Filename);
SerializeInstances(indent, terrainDescription.m_Instances);
m_OutputFile << indentStr << "}" << (noComma ? "" : ",") << "\n";
}

void SceneLoaderJSON::SerializeInstances(int indent, std::vector<Terrain::Instance> const& instances)
{
std::string indentStr(indent, ' ');
m_OutputFile << indentStr << "\"instances\":\n";
m_OutputFile << indentStr << "[\n";
indent += 4;
size_t instanceCount = instances.size();
size_t instanceIndex = 0;
for (auto& instance : instances)
{
bool noComma = ((instanceIndex + 1) == instanceCount);
SerializeInstance(indent, instance, noComma);
++instanceIndex;
}
m_OutputFile << indentStr << "]\n";
}

void SceneLoaderJSON::SerializeInstance(int indent, Terrain::Instance const& instance, bool noComma)
{
std::string indentStr(indent, ' ');
m_OutputFile << indentStr << "{\n";
indent += 4;
SerializeTransform(indent, instance.m_Entity, NO_COMMA);
m_OutputFile << indentStr << "}" << (noComma ? "" : ",") << "\n";
}

} // namespace GfxRenderEngine
6 changes: 3 additions & 3 deletions engine/scene/terrainLoaderJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
using namespace simdjson;

#include "engine.h"
#include "renderer/fbx.h"
#include "renderer/gltf.h"
#include "renderer/obj.h"
#include "scene/fbx.h"
#include "scene/gltf.h"
#include "scene/obj.h"
#include "scene/scene.h"

namespace GfxRenderEngine
Expand Down

0 comments on commit 3e16038

Please sign in to comment.