mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
chore: write gltf header with new writers and outputs
This commit is contained in:
parent
c27f4ed544
commit
f2438bea12
@ -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');
|
||||
|
45
src/ObjWriting/XModel/Gltf/GltfWriter.cpp
Normal file
45
src/ObjWriting/XModel/Gltf/GltfWriter.cpp
Normal 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));
|
||||
}
|
26
src/ObjWriting/XModel/Gltf/GltfWriter.h
Normal file
26
src/ObjWriting/XModel/Gltf/GltfWriter.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user