From 0b31543098a9827aeb723304bd902efe5e995f13 Mon Sep 17 00:00:00 2001 From: feiy Date: Sat, 13 Aug 2022 10:08:17 +0800 Subject: [PATCH] Adding serialization code for sparse accessors. --- tiny_gltf.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tiny_gltf.h b/tiny_gltf.h index 234e831..ce7248e 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6693,6 +6693,27 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) { if (accessor.extras.Type() != NULL_TYPE) { SerializeValue("extras", accessor.extras, o); } + + // sparse + if (accessor.sparse.isSparse) + { + json sparse; + SerializeNumberProperty("count", accessor.sparse.count, sparse); + { + json indices; + SerializeNumberProperty("bufferView", accessor.sparse.indices.bufferView, indices); + SerializeNumberProperty("byteOffset", accessor.sparse.indices.byteOffset, indices); + SerializeNumberProperty("componentType", accessor.sparse.indices.componentType, indices); + JsonAddMember(sparse, "indices", std::move(indices)); + } + { + json values; + SerializeNumberProperty("bufferView", accessor.sparse.values.bufferView, values); + SerializeNumberProperty("byteOffset", accessor.sparse.values.bufferView, values); + JsonAddMember(sparse, "values", std::move(values)); + } + JsonAddMember(o, "sparse", std::move(sparse)); + } } static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) {