diff --git a/application/lucre/UI/imgui.h b/application/lucre/UI/imgui.h index 8206be1f..2ad5c3dc 100644 --- a/application/lucre/UI/imgui.h +++ b/application/lucre/UI/imgui.h @@ -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 { diff --git a/engine/renderer/builder/fastgltfBuilder.h b/engine/renderer/builder/fastgltfBuilder.h index 74527c39..840934a0 100644 --- a/engine/renderer/builder/fastgltfBuilder.h +++ b/engine/renderer/builder/fastgltfBuilder.h @@ -29,7 +29,7 @@ #include #include "renderer/model.h" -#include "renderer/gltf.h" +#include "scene/gltf.h" #include "scene/scene.h" namespace GfxRenderEngine diff --git a/engine/renderer/builder/fbxBuilder.h b/engine/renderer/builder/fbxBuilder.h index 55362a13..d8e53a60 100644 --- a/engine/renderer/builder/fbxBuilder.h +++ b/engine/renderer/builder/fbxBuilder.h @@ -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 diff --git a/engine/renderer/builder/gltfBuilder.h b/engine/renderer/builder/gltfBuilder.h index c9384667..93bcd8c9 100644 --- a/engine/renderer/builder/gltfBuilder.h +++ b/engine/renderer/builder/gltfBuilder.h @@ -23,7 +23,7 @@ #pragma once #include "renderer/model.h" -#include "renderer/gltf.h" +#include "scene/gltf.h" #include "scene/scene.h" namespace GfxRenderEngine diff --git a/engine/renderer/builder/ufbxBuilder.h b/engine/renderer/builder/ufbxBuilder.h index 6096b63f..2b833ac5 100644 --- a/engine/renderer/builder/ufbxBuilder.h +++ b/engine/renderer/builder/ufbxBuilder.h @@ -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 diff --git a/engine/renderer/fbx.h b/engine/scene/fbx.h similarity index 100% rename from engine/renderer/fbx.h rename to engine/scene/fbx.h diff --git a/engine/renderer/gltf.h b/engine/scene/gltf.h similarity index 100% rename from engine/renderer/gltf.h rename to engine/scene/gltf.h diff --git a/engine/renderer/obj.h b/engine/scene/obj.h similarity index 100% rename from engine/renderer/obj.h rename to engine/scene/obj.h diff --git a/engine/scene/sceneLoader.h b/engine/scene/sceneLoader.h index 6f0ded64..175aa429 100644 --- a/engine/scene/sceneLoader.h +++ b/engine/scene/sceneLoader.h @@ -25,7 +25,7 @@ #include #include "engine.h" -#include "renderer/gltf.h" +#include "scene/gltf.h" #include "scene/scene.h" #include "yaml-cpp/yaml.h" diff --git a/engine/scene/sceneLoaderJSON.h b/engine/scene/sceneLoaderJSON.h index cdd6650d..84ff42c0 100644 --- a/engine/scene/sceneLoaderJSON.h +++ b/engine/scene/sceneLoaderJSON.h @@ -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 @@ -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 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 const& nodes); void SerializeNode(int indent, Gltf::Node const& node, bool noComma); @@ -109,6 +111,11 @@ namespace GfxRenderEngine void SerializeInstances(int indent, std::vector 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 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; diff --git a/engine/scene/sceneLoaderSerializeJSON.cpp b/engine/scene/sceneLoaderSerializeJSON.cpp index a90b6bef..3923a3b9 100644 --- a/engine/scene/sceneLoaderSerializeJSON.cpp +++ b/engine/scene/sceneLoaderSerializeJSON.cpp @@ -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); @@ -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 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 diff --git a/engine/scene/terrainLoaderJSON.h b/engine/scene/terrainLoaderJSON.h index 85480884..b896caf8 100644 --- a/engine/scene/terrainLoaderJSON.h +++ b/engine/scene/terrainLoaderJSON.h @@ -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