mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
chore: add json types for gltf
This commit is contained in:
parent
d4ef9fa3d9
commit
7a0930a208
256
src/ObjCommon/XModel/Gltf/JsonGltf.h
Normal file
256
src/ObjCommon/XModel/Gltf/JsonGltf.h
Normal file
@ -0,0 +1,256 @@
|
||||
#pragma once
|
||||
|
||||
#include "Json/JsonExtension.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace gltf
|
||||
{
|
||||
class JsonAsset
|
||||
{
|
||||
public:
|
||||
std::string version;
|
||||
std::optional<std::string> generator;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAsset, version, generator);
|
||||
|
||||
class JsonNode
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<float> translation;
|
||||
std::vector<float> rotation;
|
||||
std::vector<float> scale;
|
||||
std::vector<unsigned> children;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonNode, name, translation, rotation, scale, children);
|
||||
|
||||
class JsonBuffer
|
||||
{
|
||||
public:
|
||||
unsigned byteLength;
|
||||
std::optional<std::string> uri;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonBuffer, byteLength, uri);
|
||||
|
||||
enum class JsonAccessorComponentType
|
||||
{
|
||||
SIGNED_BYTE = 5120,
|
||||
UNSIGNED_BYTE = 5121,
|
||||
SIGNED_SHORT = 5122,
|
||||
UNSIGNED_SHORT = 5123,
|
||||
UNSIGNED_INT = 5125,
|
||||
FLOAT = 5126
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(JsonAccessorComponentType,
|
||||
{
|
||||
{JsonAccessorComponentType::SIGNED_BYTE, static_cast<unsigned>(JsonAccessorComponentType::SIGNED_BYTE) },
|
||||
{JsonAccessorComponentType::UNSIGNED_BYTE, static_cast<unsigned>(JsonAccessorComponentType::UNSIGNED_BYTE) },
|
||||
{JsonAccessorComponentType::SIGNED_SHORT, static_cast<unsigned>(JsonAccessorComponentType::SIGNED_SHORT) },
|
||||
{JsonAccessorComponentType::UNSIGNED_SHORT, static_cast<unsigned>(JsonAccessorComponentType::UNSIGNED_SHORT)},
|
||||
{JsonAccessorComponentType::UNSIGNED_INT, static_cast<unsigned>(JsonAccessorComponentType::UNSIGNED_INT) },
|
||||
{JsonAccessorComponentType::FLOAT, static_cast<unsigned>(JsonAccessorComponentType::FLOAT) },
|
||||
});
|
||||
|
||||
enum class JsonAccessorType
|
||||
{
|
||||
SCALAR,
|
||||
VEC2,
|
||||
VEC3,
|
||||
VEC4,
|
||||
MAT2,
|
||||
MAT3,
|
||||
MAT4
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(JsonAccessorType,
|
||||
{
|
||||
{JsonAccessorType::SCALAR, "SCALAR"},
|
||||
{JsonAccessorType::VEC2, "VEC2" },
|
||||
{JsonAccessorType::VEC3, "VEC3" },
|
||||
{JsonAccessorType::VEC4, "VEC4" },
|
||||
{JsonAccessorType::MAT2, "MAT2" },
|
||||
{JsonAccessorType::MAT3, "MAT3" },
|
||||
{JsonAccessorType::MAT4, "MAT4" },
|
||||
});
|
||||
|
||||
class JsonAccessor
|
||||
{
|
||||
public:
|
||||
std::optional<unsigned> bufferView;
|
||||
std::optional<unsigned> byteOffset;
|
||||
JsonAccessorComponentType componentType;
|
||||
// std::optional<boolean> normalized
|
||||
unsigned count;
|
||||
JsonAccessorType type;
|
||||
std::optional<std::vector<float>> max;
|
||||
std::optional<std::vector<float>> min;
|
||||
// std::optional<JsonAccessorSparse> sparse;
|
||||
// std::optional<std::string> name;
|
||||
// extensions
|
||||
// extras
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAccessor, bufferView, byteOffset, componentType, count, type, min, max);
|
||||
|
||||
class JsonBufferView
|
||||
{
|
||||
public:
|
||||
unsigned buffer;
|
||||
unsigned byteLength;
|
||||
unsigned byteOffset;
|
||||
unsigned target;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonBufferView, buffer, byteLength, byteOffset, target);
|
||||
|
||||
enum class JsonAnimationChannelTargetPath
|
||||
{
|
||||
TRANSLATION,
|
||||
ROTATION,
|
||||
SCALE,
|
||||
WEIGHTS
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(JsonAnimationChannelTargetPath,
|
||||
{
|
||||
{JsonAnimationChannelTargetPath::TRANSLATION, "translation"},
|
||||
{JsonAnimationChannelTargetPath::ROTATION, "rotation" },
|
||||
{JsonAnimationChannelTargetPath::SCALE, "scale" },
|
||||
{JsonAnimationChannelTargetPath::WEIGHTS, "weights" },
|
||||
});
|
||||
|
||||
class JsonAnimationChannelTarget
|
||||
{
|
||||
public:
|
||||
unsigned node;
|
||||
JsonAnimationChannelTargetPath path;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimationChannelTarget, node, path);
|
||||
|
||||
class JsonAnimationChannel
|
||||
{
|
||||
public:
|
||||
unsigned sampler;
|
||||
JsonAnimationChannelTarget target;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimationChannel, sampler, target);
|
||||
|
||||
enum class JsonAnimationSamplerInterpolation
|
||||
{
|
||||
LINEAR,
|
||||
STEP,
|
||||
CUBIC_SPLINE
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(JsonAnimationSamplerInterpolation,
|
||||
{
|
||||
{JsonAnimationSamplerInterpolation::LINEAR, "LINEAR" },
|
||||
{JsonAnimationSamplerInterpolation::STEP, "STEP" },
|
||||
{JsonAnimationSamplerInterpolation::CUBIC_SPLINE, "CUBICSPLINE"},
|
||||
});
|
||||
|
||||
class JsonAnimationSampler
|
||||
{
|
||||
public:
|
||||
unsigned input;
|
||||
std::optional<JsonAnimationSamplerInterpolation> interpolation;
|
||||
unsigned output;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimationSampler, input);
|
||||
|
||||
class JsonAnimation
|
||||
{
|
||||
public:
|
||||
std::vector<JsonAnimationChannel> channels;
|
||||
std::vector<JsonAnimationSampler> samplers;
|
||||
std::optional<std::string> name;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimation, channels, samplers, name);
|
||||
|
||||
class JsonMaterial
|
||||
{
|
||||
public:
|
||||
std::optional<std::string> name;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMaterial, name);
|
||||
|
||||
enum class JsonMeshPrimitivesMode
|
||||
{
|
||||
POINTS = 0,
|
||||
LINES = 1,
|
||||
LINE_LOOP = 2,
|
||||
LINE_STRIP = 3,
|
||||
TRIANGLES = 4,
|
||||
TRIANGLES_STRIP = 5,
|
||||
TRIANGLE_FAN = 6
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(JsonMeshPrimitivesMode,
|
||||
{
|
||||
{JsonMeshPrimitivesMode::POINTS, static_cast<unsigned>(JsonMeshPrimitivesMode::POINTS) },
|
||||
{JsonMeshPrimitivesMode::LINES, static_cast<unsigned>(JsonMeshPrimitivesMode::LINES) },
|
||||
{JsonMeshPrimitivesMode::LINE_LOOP, static_cast<unsigned>(JsonMeshPrimitivesMode::LINE_LOOP) },
|
||||
{JsonMeshPrimitivesMode::LINE_STRIP, static_cast<unsigned>(JsonMeshPrimitivesMode::LINE_STRIP) },
|
||||
{JsonMeshPrimitivesMode::TRIANGLES, static_cast<unsigned>(JsonMeshPrimitivesMode::TRIANGLES) },
|
||||
{JsonMeshPrimitivesMode::TRIANGLES_STRIP, static_cast<unsigned>(JsonMeshPrimitivesMode::TRIANGLES_STRIP)},
|
||||
{JsonMeshPrimitivesMode::TRIANGLE_FAN, static_cast<unsigned>(JsonMeshPrimitivesMode::TRIANGLE_FAN) },
|
||||
});
|
||||
|
||||
class JsonMeshPrimitives
|
||||
{
|
||||
public:
|
||||
std::unordered_map<std::string, unsigned> attributes;
|
||||
std::optional<unsigned> indices;
|
||||
std::optional<unsigned> material;
|
||||
std::optional<JsonMeshPrimitivesMode> mode;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMeshPrimitives, attributes, indices, material, mode);
|
||||
|
||||
class JsonMesh
|
||||
{
|
||||
public:
|
||||
std::vector<JsonMeshPrimitives> primitives;
|
||||
std::optional<std::vector<float>> weights;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMesh, primitives, weights);
|
||||
|
||||
class JsonSkin
|
||||
{
|
||||
public:
|
||||
std::optional<unsigned> inverseBindMatrices;
|
||||
std::optional<unsigned> skeleton;
|
||||
std::vector<unsigned> joints;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonSkin, inverseBindMatrices, skeleton, joints);
|
||||
|
||||
class JsonRoot
|
||||
{
|
||||
public:
|
||||
std::vector<JsonAccessor> accessors;
|
||||
std::vector<JsonAnimation> animations;
|
||||
JsonAsset asset;
|
||||
std::vector<JsonBuffer> buffers;
|
||||
std::vector<JsonBufferView> bufferViews;
|
||||
std::vector<JsonMaterial> materials;
|
||||
std::vector<JsonMesh> meshes;
|
||||
std::vector<JsonNode> nodes;
|
||||
std::vector<JsonSkin> skins;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonRoot, asset);
|
||||
} // namespace gltf
|
Loading…
x
Reference in New Issue
Block a user