diff --git a/src/ObjCommon/XModel/Gltf/GltfConstants.h b/src/ObjCommon/XModel/Gltf/GltfConstants.h index e8d3001a..1ce687d0 100644 --- a/src/ObjCommon/XModel/Gltf/GltfConstants.h +++ b/src/ObjCommon/XModel/Gltf/GltfConstants.h @@ -8,6 +8,7 @@ namespace gltf { constexpr uint32_t GLTF_MAGIC = FileUtils::MakeMagic32('g', 'l', 'T', 'F'); constexpr uint32_t GLTF_VERSION = 2u; + constexpr auto GLTF_VERSION_STRING = "2.0"; constexpr uint32_t CHUNK_MAGIC_JSON = FileUtils::MakeMagic32('J', 'S', 'O', 'N'); constexpr uint32_t CHUNK_MAGIC_BIN = FileUtils::MakeMagic32('B', 'I', 'N', '\x00'); diff --git a/src/ObjWriting/XModel/Gltf/GltfWriter.cpp b/src/ObjWriting/XModel/Gltf/GltfWriter.cpp new file mode 100644 index 00000000..3aa03f9b --- /dev/null +++ b/src/ObjWriting/XModel/Gltf/GltfWriter.cpp @@ -0,0 +1,45 @@ +#include "GltfWriter.h" + +#include "GitVersion.h" +#include "XModel/Gltf/GltfConstants.h" +#include "XModel/Gltf/JsonGltf.h" + +using namespace gltf; +using namespace nlohmann; + +namespace +{ + constexpr auto GLTF_GENERATOR = "OpenAssetTools " GIT_VERSION; + + class GltfWriterImpl final : public gltf::Writer + { + public: + GltfWriterImpl(const Output* output, std::string gameName, std::string zoneName) + : m_output(output), + m_game_name(std::move(gameName)), + m_zone_name(std::move(zoneName)) + { + } + + void Write(std::ostream& stream) override + { + JsonRoot gltf; + gltf.asset.version = GLTF_VERSION_STRING; + gltf.asset.generator = GLTF_GENERATOR; + + const json jRoot = gltf; + m_output->EmitJson(jRoot); + m_output->Finalize(); + } + + private: + const Output* m_output; + std::string m_game_name; + std::string m_zone_name; + }; +} // namespace + +std::unique_ptr Writer::CreateWriter(const Output* output, std::string gameName, std::string zoneName) +{ + return std::make_unique(output, std::move(gameName), std::move(zoneName)); +} diff --git a/src/ObjWriting/XModel/Gltf/GltfWriter.h b/src/ObjWriting/XModel/Gltf/GltfWriter.h new file mode 100644 index 00000000..3d69d77e --- /dev/null +++ b/src/ObjWriting/XModel/Gltf/GltfWriter.h @@ -0,0 +1,26 @@ +#pragma once + +#include "GltfOutput.h" +#include "XModel/AbstractXModelWriter.h" +#include "XModel/Gltf/JsonGltf.h" + +#include +#include + +namespace gltf +{ + class Writer : public AbstractXModelWriter + { + public: + Writer() = default; + virtual ~Writer() = default; + Writer(const Writer& other) = default; + Writer(Writer&& other) noexcept = default; + Writer& operator=(const Writer& other) = default; + Writer& operator=(Writer&& other) noexcept = default; + + virtual void Write(std::ostream& stream) = 0; + + static std::unique_ptr CreateWriter(const Output* output, std::string gameName, std::string zoneName); + }; +} // namespace gltf