mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-15 11:15:57 +08:00
adding missing extras field serializaton
This commit is contained in:
parent
a48f12d2fc
commit
b3af2f1cf6
68
tiny_gltf.h
68
tiny_gltf.h
@ -398,6 +398,7 @@ struct AnimationSampler {
|
|||||||
int output; // required
|
int output; // required
|
||||||
std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE",
|
std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE",
|
||||||
// "CUBICSPLINE"], default "LINEAR"
|
// "CUBICSPLINE"], default "LINEAR"
|
||||||
|
Value extras;
|
||||||
|
|
||||||
AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {}
|
AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {}
|
||||||
};
|
};
|
||||||
@ -2559,6 +2560,7 @@ static bool ParseAnimation(Animation *animation, std::string *err,
|
|||||||
}
|
}
|
||||||
sampler.input = static_cast<int>(inputIndex);
|
sampler.input = static_cast<int>(inputIndex);
|
||||||
sampler.output = static_cast<int>(outputIndex);
|
sampler.output = static_cast<int>(outputIndex);
|
||||||
|
ParseExtrasProperty(&(sampler.extras), s);
|
||||||
animation->samplers.push_back(sampler);
|
animation->samplers.push_back(sampler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3675,6 +3677,10 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SerializeStringProperty("type", type, o);
|
SerializeStringProperty("type", type, o);
|
||||||
|
|
||||||
|
if (accessor.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", accessor.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
|
static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
|
||||||
@ -3684,12 +3690,20 @@ static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {
|
|||||||
SerializeStringProperty("path", channel.target_path, target);
|
SerializeStringProperty("path", channel.target_path, target);
|
||||||
|
|
||||||
o["target"] = target;
|
o["target"] = target;
|
||||||
|
|
||||||
|
if (channel.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", channel.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfAnimationSampler(AnimationSampler &sampler, json &o) {
|
static void SerializeGltfAnimationSampler(AnimationSampler &sampler, json &o) {
|
||||||
SerializeNumberProperty("input", sampler.input, o);
|
SerializeNumberProperty("input", sampler.input, o);
|
||||||
SerializeNumberProperty("output", sampler.output, o);
|
SerializeNumberProperty("output", sampler.output, o);
|
||||||
SerializeStringProperty("interpolation", sampler.interpolation, o);
|
SerializeStringProperty("interpolation", sampler.interpolation, o);
|
||||||
|
|
||||||
|
if (sampler.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", sampler.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfAnimation(Animation &animation, json &o) {
|
static void SerializeGltfAnimation(Animation &animation, json &o) {
|
||||||
@ -3712,6 +3726,10 @@ static void SerializeGltfAnimation(Animation &animation, json &o) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
o["samplers"] = samplers;
|
o["samplers"] = samplers;
|
||||||
|
|
||||||
|
if (animation.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", animation.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfAsset(Asset &asset, json &o) {
|
static void SerializeGltfAsset(Asset &asset, json &o) {
|
||||||
@ -3735,6 +3753,10 @@ static void SerializeGltfBuffer(Buffer &buffer, json &o) {
|
|||||||
SerializeGltfBufferData(buffer.data, o);
|
SerializeGltfBufferData(buffer.data, o);
|
||||||
|
|
||||||
if (buffer.name.size()) SerializeStringProperty("name", buffer.name, o);
|
if (buffer.name.size()) SerializeStringProperty("name", buffer.name, o);
|
||||||
|
|
||||||
|
if (buffer.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", buffer.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfBuffer(Buffer &buffer, json &o,
|
static void SerializeGltfBuffer(Buffer &buffer, json &o,
|
||||||
@ -3745,6 +3767,10 @@ static void SerializeGltfBuffer(Buffer &buffer, json &o,
|
|||||||
SerializeStringProperty("uri", binBaseFilename, o);
|
SerializeStringProperty("uri", binBaseFilename, o);
|
||||||
|
|
||||||
if (buffer.name.size()) SerializeStringProperty("name", buffer.name, o);
|
if (buffer.name.size()) SerializeStringProperty("name", buffer.name, o);
|
||||||
|
|
||||||
|
if (buffer.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", buffer.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfBufferView(BufferView &bufferView, json &o) {
|
static void SerializeGltfBufferView(BufferView &bufferView, json &o) {
|
||||||
@ -3767,6 +3793,10 @@ static void SerializeGltfBufferView(BufferView &bufferView, json &o) {
|
|||||||
if (bufferView.name.size()) {
|
if (bufferView.name.size()) {
|
||||||
SerializeStringProperty("name", bufferView.name, o);
|
SerializeStringProperty("name", bufferView.name, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bufferView.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", bufferView.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfImage(Image &image, json &o) {
|
static void SerializeGltfImage(Image &image, json &o) {
|
||||||
@ -3775,6 +3805,10 @@ static void SerializeGltfImage(Image &image, json &o) {
|
|||||||
if (image.name.size()) {
|
if (image.name.size()) {
|
||||||
SerializeStringProperty("name", image.name, o);
|
SerializeStringProperty("name", image.name, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (image.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", image.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfMaterial(Material &material, json &o) {
|
static void SerializeGltfMaterial(Material &material, json &o) {
|
||||||
@ -3792,6 +3826,10 @@ static void SerializeGltfMaterial(Material &material, json &o) {
|
|||||||
if (material.name.size()) {
|
if (material.name.size()) {
|
||||||
SerializeStringProperty("name", material.name, o);
|
SerializeStringProperty("name", material.name, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (material.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", material.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfMesh(Mesh &mesh, json &o) {
|
static void SerializeGltfMesh(Mesh &mesh, json &o) {
|
||||||
@ -3836,6 +3874,10 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) {
|
|||||||
primitive["targets"] = targets;
|
primitive["targets"] = targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gltfPrimitive.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", gltfPrimitive.extras, primitive);
|
||||||
|
}
|
||||||
|
|
||||||
primitives.push_back(primitive);
|
primitives.push_back(primitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3847,6 +3889,10 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) {
|
|||||||
if (mesh.name.size()) {
|
if (mesh.name.size()) {
|
||||||
SerializeStringProperty("name", mesh.name, o);
|
SerializeStringProperty("name", mesh.name, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mesh.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", mesh.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfLight(Light &light, json &o) {
|
static void SerializeGltfLight(Light &light, json &o) {
|
||||||
@ -3894,6 +3940,10 @@ static void SerializeGltfSampler(Sampler &sampler, json &o) {
|
|||||||
SerializeNumberProperty("minFilter", sampler.minFilter, o);
|
SerializeNumberProperty("minFilter", sampler.minFilter, o);
|
||||||
SerializeNumberProperty("wrapS", sampler.wrapS, o);
|
SerializeNumberProperty("wrapS", sampler.wrapS, o);
|
||||||
SerializeNumberProperty("wrapT", sampler.wrapT, o);
|
SerializeNumberProperty("wrapT", sampler.wrapT, o);
|
||||||
|
|
||||||
|
if (sampler.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", sampler.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfOrthographicCamera(const OrthographicCamera &camera,
|
static void SerializeGltfOrthographicCamera(const OrthographicCamera &camera,
|
||||||
@ -3902,6 +3952,10 @@ static void SerializeGltfOrthographicCamera(const OrthographicCamera &camera,
|
|||||||
SerializeNumberProperty("znear", camera.znear, o);
|
SerializeNumberProperty("znear", camera.znear, o);
|
||||||
SerializeNumberProperty("xmag", camera.xmag, o);
|
SerializeNumberProperty("xmag", camera.xmag, o);
|
||||||
SerializeNumberProperty("ymag", camera.ymag, o);
|
SerializeNumberProperty("ymag", camera.ymag, o);
|
||||||
|
|
||||||
|
if (camera.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", camera.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfPerspectiveCamera(const PerspectiveCamera &camera,
|
static void SerializeGltfPerspectiveCamera(const PerspectiveCamera &camera,
|
||||||
@ -3915,6 +3969,10 @@ static void SerializeGltfPerspectiveCamera(const PerspectiveCamera &camera,
|
|||||||
if (camera.yfov > 0) {
|
if (camera.yfov > 0) {
|
||||||
SerializeNumberProperty("yfov", camera.yfov, o);
|
SerializeNumberProperty("yfov", camera.yfov, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (camera.extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", camera.extras, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SerializeGltfCamera(const Camera &camera, json &o) {
|
static void SerializeGltfCamera(const Camera &camera, json &o) {
|
||||||
@ -3942,7 +4000,7 @@ static void SerializeGltfScene(Scene &scene, json &o) {
|
|||||||
if (scene.name.size()) {
|
if (scene.name.size()) {
|
||||||
SerializeStringProperty("name", scene.name, o);
|
SerializeStringProperty("name", scene.name, o);
|
||||||
}
|
}
|
||||||
if (scene.extras.Keys().size()) {
|
if (scene.extras.Type() != NULL_TYPE) {
|
||||||
SerializeValue("extras", scene.extras, o);
|
SerializeValue("extras", scene.extras, o);
|
||||||
}
|
}
|
||||||
SerializeExtensionMap(scene.extensions, o);
|
SerializeExtensionMap(scene.extensions, o);
|
||||||
@ -3965,8 +4023,7 @@ static void SerializeGltfTexture(Texture &texture, json &o) {
|
|||||||
}
|
}
|
||||||
SerializeNumberProperty("source", texture.source, o);
|
SerializeNumberProperty("source", texture.source, o);
|
||||||
|
|
||||||
if (texture.extras.Size()) {
|
if (texture.extras.Type() != NULL_TYPE) {
|
||||||
json extras;
|
|
||||||
SerializeValue("extras", texture.extras, o);
|
SerializeValue("extras", texture.extras, o);
|
||||||
}
|
}
|
||||||
SerializeExtensionMap(texture.extensions, o);
|
SerializeExtensionMap(texture.extensions, o);
|
||||||
@ -4193,6 +4250,11 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
output["extensions"] = ext_j;
|
output["extensions"] = ext_j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EXTRAS
|
||||||
|
if (model->extras.Type() != NULL_TYPE) {
|
||||||
|
SerializeValue("extras", model->extras, output);
|
||||||
|
}
|
||||||
|
|
||||||
WriteGltfFile(filename, output.dump());
|
WriteGltfFile(filename, output.dump());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user