From 81b672bcc2d9e74a3db34ea8ddd6e04afd2af087 Mon Sep 17 00:00:00 2001 From: Selmar Kok Date: Fri, 18 Oct 2019 16:08:44 +0200 Subject: [PATCH] add some missing serialization // add mesh==() weights comparison // use const iterator for extension serialization --- tiny_gltf.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index e2bd4a6..01a5278 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1903,7 +1903,8 @@ bool Material::operator==(const Material &other) const { } bool Mesh::operator==(const Mesh &other) const { return this->extensions == other.extensions && this->extras == other.extras && - this->name == other.name && this->primitives == other.primitives; + this->name == other.name && Equals(this->weights, other.weights) && + this->primitives == other.primitives; } bool Model::operator==(const Model &other) const { return this->accessors == other.accessors && @@ -5958,11 +5959,11 @@ static void SerializeParameterMap(ParameterMap ¶m, json &o) { } #endif -static void SerializeExtensionMap(ExtensionMap &extensions, json &o) { +static void SerializeExtensionMap(const ExtensionMap &extensions, json &o) { if (!extensions.size()) return; json extMap; - for (ExtensionMap::iterator extIt = extensions.begin(); + for (ExtensionMap::const_iterator extIt = extensions.begin(); extIt != extensions.end(); ++extIt) { // Allow an empty object for extension(#97) json ret; @@ -6388,6 +6389,8 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) { JsonAddMember(primitive, "targets", std::move(targets)); } + SerializeExtensionMap(gltfPrimitive.extensions, o); + if (gltfPrimitive.extras.Type() != NULL_TYPE) { SerializeValue("extras", gltfPrimitive.extras, primitive); } @@ -6405,6 +6408,7 @@ static void SerializeGltfMesh(Mesh &mesh, json &o) { SerializeStringProperty("name", mesh.name, o); } + SerializeExtensionMap(mesh.extensions, o); if (mesh.extras.Type() != NULL_TYPE) { SerializeValue("extras", mesh.extras, o); } @@ -6414,6 +6418,9 @@ static void SerializeSpotLight(SpotLight &spot, json &o) { SerializeNumberProperty("innerConeAngle", spot.innerConeAngle, o); SerializeNumberProperty("outerConeAngle", spot.outerConeAngle, o); SerializeExtensionMap(spot.extensions, o); + if (spot.extras.Type() != NULL_TYPE) { + SerializeValue("extras", spot.extras, o); + } } static void SerializeGltfLight(Light &light, json &o) { @@ -6427,6 +6434,10 @@ static void SerializeGltfLight(Light &light, json &o) { SerializeSpotLight(light.spot, spot); JsonAddMember(o, "spot", std::move(spot)); } + SerializeExtensionMap(light.extensions, o); + if (light.extras.Type() != NULL_TYPE) { + SerializeValue("extras", light.extras, o); + } } static void SerializeGltfNode(Node &node, json &o) {