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
3 changed files with 72 additions and 0 deletions

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