#pragma once #include "Json/JsonExtension.h" #include #include #include #include #include namespace gltf { class JsonAsset { public: std::string version; std::optional generator; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAsset, version, generator); class JsonNode { public: std::optional name; std::optional> translation; std::optional> rotation; std::optional> scale; std::optional> matrix; std::optional> children; std::optional skin; std::optional mesh; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonNode, name, translation, rotation, scale, matrix, children, skin, mesh); class JsonBuffer { public: unsigned byteLength; std::optional 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(JsonAccessorComponentType::SIGNED_BYTE) }, {JsonAccessorComponentType::UNSIGNED_BYTE, static_cast(JsonAccessorComponentType::UNSIGNED_BYTE) }, {JsonAccessorComponentType::SIGNED_SHORT, static_cast(JsonAccessorComponentType::SIGNED_SHORT) }, {JsonAccessorComponentType::UNSIGNED_SHORT, static_cast(JsonAccessorComponentType::UNSIGNED_SHORT)}, {JsonAccessorComponentType::UNSIGNED_INT, static_cast(JsonAccessorComponentType::UNSIGNED_INT) }, {JsonAccessorComponentType::FLOAT, static_cast(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 bufferView; std::optional byteOffset; JsonAccessorComponentType componentType; // std::optional normalized unsigned count; JsonAccessorType type; std::optional> max; std::optional> min; // std::optional sparse; // std::optional name; // extensions // extras }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAccessor, bufferView, byteOffset, componentType, count, type, min, max); enum class JsonBufferViewTarget { ARRAY_BUFFER = 34962, ELEMENT_ARRAY_BUFFER = 34963 }; NLOHMANN_JSON_SERIALIZE_ENUM(JsonBufferViewTarget, { {JsonBufferViewTarget::ARRAY_BUFFER, static_cast(JsonBufferViewTarget::ARRAY_BUFFER) }, {JsonBufferViewTarget::ELEMENT_ARRAY_BUFFER, static_cast(JsonBufferViewTarget::ELEMENT_ARRAY_BUFFER)}, }); class JsonBufferView { public: unsigned buffer; unsigned byteLength; std::optional byteOffset; std::optional byteStride; std::optional target; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonBufferView, buffer, byteLength, byteOffset, byteStride, 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 interpolation; unsigned output; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimationSampler, input, interpolation, output); class JsonAnimation { public: std::vector channels; std::vector samplers; std::optional name; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonAnimation, channels, samplers, name); class JsonTextureInfo { public: unsigned index; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonTextureInfo, index); class JsonPbrMetallicRoughness { public: std::optional baseColorTexture; std::optional metallicFactor; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonPbrMetallicRoughness, baseColorTexture, metallicFactor); class JsonNormalTextureInfo { public: unsigned index; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonNormalTextureInfo, index); class JsonMaterial { public: std::optional name; std::optional pbrMetallicRoughness; std::optional normalTexture; std::optional doubleSided; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMaterial, name, pbrMetallicRoughness, normalTexture, doubleSided); 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(JsonMeshPrimitivesMode::POINTS) }, {JsonMeshPrimitivesMode::LINES, static_cast(JsonMeshPrimitivesMode::LINES) }, {JsonMeshPrimitivesMode::LINE_LOOP, static_cast(JsonMeshPrimitivesMode::LINE_LOOP) }, {JsonMeshPrimitivesMode::LINE_STRIP, static_cast(JsonMeshPrimitivesMode::LINE_STRIP) }, {JsonMeshPrimitivesMode::TRIANGLES, static_cast(JsonMeshPrimitivesMode::TRIANGLES) }, {JsonMeshPrimitivesMode::TRIANGLES_STRIP, static_cast(JsonMeshPrimitivesMode::TRIANGLES_STRIP)}, {JsonMeshPrimitivesMode::TRIANGLE_FAN, static_cast(JsonMeshPrimitivesMode::TRIANGLE_FAN) }, }); // This should probably be a map, but the supported models do not have arbitrary primitives anyway class JsonMeshPrimitivesAttributes { public: std::optional POSITION; std::optional NORMAL; std::optional COLOR_0; std::optional TEXCOORD_0; std::optional JOINTS_0; std::optional WEIGHTS_0; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMeshPrimitivesAttributes, POSITION, NORMAL, TEXCOORD_0, JOINTS_0, WEIGHTS_0); class JsonMeshPrimitives { public: JsonMeshPrimitivesAttributes attributes; std::optional indices; std::optional material; std::optional mode; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMeshPrimitives, attributes, indices, material, mode); class JsonMesh { public: std::vector primitives; std::optional> weights; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonMesh, primitives, weights); class JsonSkin { public: std::optional inverseBindMatrices; std::optional skeleton; std::vector joints; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonSkin, inverseBindMatrices, skeleton, joints); class JsonScene { public: std::vector nodes; std::optional name; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonScene, nodes, name); class JsonTexture { public: unsigned source; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonTexture, source); class JsonImage { public: std::optional uri; }; NLOHMANN_DEFINE_TYPE_EXTENSION(JsonImage, uri); class JsonRoot { public: std::optional> accessors; std::optional> animations; JsonAsset asset; std::optional> buffers; std::optional> bufferViews; std::optional> images; std::optional> materials; std::optional> meshes; std::optional> nodes; std::optional> skins; std::optional scene; std::optional> scenes; std::optional> textures; }; NLOHMANN_DEFINE_TYPE_EXTENSION( JsonRoot, accessors, animations, asset, buffers, bufferViews, images, materials, meshes, nodes, skins, scene, scenes, textures); } // namespace gltf