From 9a3686ccb64221d9f52c6e3323e558662c163856 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Thu, 23 Dec 2021 19:40:50 +0100 Subject: [PATCH] Fixed metallic material import for GLTF --- libraries/model-serializers/src/GLTFSerializer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/model-serializers/src/GLTFSerializer.cpp b/libraries/model-serializers/src/GLTFSerializer.cpp index 9aadf951cc..99d4c31453 100755 --- a/libraries/model-serializers/src/GLTFSerializer.cpp +++ b/libraries/model-serializers/src/GLTFSerializer.cpp @@ -495,9 +495,13 @@ bool GLTFSerializer::addMaterial(const QJsonObject& object) { getIndexFromObject(jsMetallicRoughness, "baseColorTexture", material.pbrMetallicRoughness.baseColorTexture, material.pbrMetallicRoughness.defined); - getDoubleVal(jsMetallicRoughness, "metallicFactor", + // Undefined metallicFactor used with pbrMetallicRoughness means metallicFactor == 1.0 + if (!getDoubleVal(jsMetallicRoughness, "metallicFactor", material.pbrMetallicRoughness.metallicFactor, - material.pbrMetallicRoughness.defined); + material.pbrMetallicRoughness.defined)) { + material.pbrMetallicRoughness.metallicFactor = 1.0; + material.pbrMetallicRoughness.defined["metallicFactor"] = true; + } getDoubleVal(jsMetallicRoughness, "roughnessFactor", material.pbrMetallicRoughness.roughnessFactor, material.pbrMetallicRoughness.defined); @@ -1856,6 +1860,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const GLTFMaterial& mat if (material.pbrMetallicRoughness.defined["metallicFactor"]) { hfmMat.metallic = material.pbrMetallicRoughness.metallicFactor; + hfmMat._material->setMetallic(hfmMat.metallic); } if (material.pbrMetallicRoughness.defined["baseColorTexture"]) { hfmMat.opacityTexture = getHFMTexture(_file.textures[material.pbrMetallicRoughness.baseColorTexture]);