From 4fa77b6f728b6be3d2e7fc74dda97b835476f797 Mon Sep 17 00:00:00 2001
From: Cosmic Linden <cosmic@lindenlab.com>
Date: Mon, 12 Dec 2022 14:12:03 -0800
Subject: [PATCH] SL-18820: Update LLGLTFMaterial: Add setBaseMaterial() and
 equality comparison

---
 indra/llprimitive/llgltfmaterial.cpp | 33 ++++++++++++++++++++++++++++
 indra/llprimitive/llgltfmaterial.h   |  7 +++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp
index c98fd7d1ee5..5442af33d00 100644
--- a/indra/llprimitive/llgltfmaterial.cpp
+++ b/indra/llprimitive/llgltfmaterial.cpp
@@ -98,6 +98,29 @@ LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs)
     return *this;
 }
 
+bool LLGLTFMaterial::operator==(const LLGLTFMaterial& rhs) const
+{
+    return mBaseColorId == rhs.mBaseColorId &&
+        mNormalId == rhs.mNormalId &&
+        mMetallicRoughnessId == rhs.mMetallicRoughnessId &&
+        mEmissiveId == rhs.mEmissiveId &&
+
+        mBaseColor == rhs.mBaseColor &&
+        mEmissiveColor == rhs.mEmissiveColor &&
+        
+        mMetallicFactor == rhs.mMetallicFactor &&
+        mRoughnessFactor == rhs.mRoughnessFactor &&
+        mAlphaCutoff == rhs.mAlphaCutoff &&
+
+        mDoubleSided == rhs.mDoubleSided &&
+        mAlphaMode == rhs.mAlphaMode &&
+
+        mTextureTransform == rhs.mTextureTransform &&
+
+        mOverrideDoubleSided == rhs.mOverrideDoubleSided &&
+        mOverrideAlphaMode == rhs.mOverrideAlphaMode;
+}
+
 bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, std::string& error_msg)
 {
     LL_PROFILE_ZONE_SCOPED;
@@ -365,6 +388,16 @@ void LLGLTFMaterial::writeToTexture(tinygltf::Model& model, T& texture_info, Tex
     texture_info.extensions[GLTF_FILE_EXTENSION_TRANSFORM] = tinygltf::Value(transform_map);
 }
 
+bool LLGLTFMaterial::setBaseMaterial()
+{
+    const LLGLTFMaterial old_override = *this;
+    *this = sDefault;
+    // Preserve the texture transforms
+    mTextureTransform = old_override.mTextureTransform;
+    return *this != old_override;
+}
+
+
 // static
 void LLGLTFMaterial::hackOverrideUUID(LLUUID& id)
 {
diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h
index aa49a58f0c3..7bfcd3bf661 100644
--- a/indra/llprimitive/llgltfmaterial.h
+++ b/indra/llprimitive/llgltfmaterial.h
@@ -71,6 +71,8 @@ class LLGLTFMaterial : public LLRefCount
     LLGLTFMaterial(const LLGLTFMaterial& rhs);
 
     LLGLTFMaterial& operator=(const LLGLTFMaterial& rhs);
+    bool operator==(const LLGLTFMaterial& rhs) const;
+    bool operator!=(const LLGLTFMaterial& rhs) const { return !(*this == rhs); }
 
     LLUUID mBaseColorId;
     LLUUID mNormalId;
@@ -101,7 +103,6 @@ class LLGLTFMaterial : public LLRefCount
         md5.finalize();
         LLUUID id;
         md5.raw_digest(id.mData);
-        // *TODO: Hash the overrides
         return id;
     }
 
@@ -181,6 +182,10 @@ class LLGLTFMaterial : public LLRefCount
 
     void applyOverride(const LLGLTFMaterial& override_mat);
 
+    // For material overrides only. Clears most properties to
+    // default/fallthrough, but preserves the transforms.
+    bool setBaseMaterial();
+
 private:
 
     template<typename T>
-- 
GitLab