chore: write gltf header with new writers and outputs

This commit is contained in:
Jan 2024-03-30 17:12:48 +01:00
parent c27f4ed544
commit f2438bea12
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
3 changed files with 72 additions and 0 deletions

View File

@ -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');

View File

@ -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> Writer::CreateWriter(const Output* output, std::string gameName, std::string zoneName)
{
return std::make_unique<GltfWriterImpl>(output, std::move(gameName), std::move(zoneName));
}

View File

@ -0,0 +1,26 @@
#pragma once
#include "GltfOutput.h"
#include "XModel/AbstractXModelWriter.h"
#include "XModel/Gltf/JsonGltf.h"
#include <memory>
#include <ostream>
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<Writer> CreateWriter(const Output* output, std::string gameName, std::string zoneName);
};
} // namespace gltf