From 7e009041e35b999fd1e47c0f0e42cadcf8f5c31c Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Fri, 13 Sep 2019 15:32:22 +0900 Subject: [PATCH] Do not serialize pbrMetallicRoughness when they have all default values. Fixes #204 --- tiny_gltf.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 13df372..e2bd4a6 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6314,7 +6314,15 @@ static void SerializeGltfMaterial(Material &material, json &o) { json pbrMetallicRoughness; SerializeGltfPbrMetallicRoughness(material.pbrMetallicRoughness, pbrMetallicRoughness); - JsonAddMember(o, "pbrMetallicRoughness", std::move(pbrMetallicRoughness)); + // Issue 204 + // Do not serialize `pbrMetallicRoughness` if pbrMetallicRoughness has all + // default values(json is null). Otherwise it will serialize to + // `pbrMetallicRoughness : null`, which cannot be read by other glTF + // importers(and validators). + // + if (!JsonIsNull(pbrMetallicRoughness)) { + JsonAddMember(o, "pbrMetallicRoughness", std::move(pbrMetallicRoughness)); + } } #if 0 // legacy way. just for the record.