Skip to content
Snippets Groups Projects
Commit 4fa77b6f authored by Cosmic Linden's avatar Cosmic Linden
Browse files

SL-18820: Update LLGLTFMaterial: Add setBaseMaterial() and equality comparison

parent a710bf90
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
...@@ -98,6 +98,29 @@ LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs) ...@@ -98,6 +98,29 @@ LLGLTFMaterial& LLGLTFMaterial::operator=(const LLGLTFMaterial& rhs)
return *this; 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) bool LLGLTFMaterial::fromJSON(const std::string& json, std::string& warn_msg, std::string& error_msg)
{ {
LL_PROFILE_ZONE_SCOPED; LL_PROFILE_ZONE_SCOPED;
...@@ -365,6 +388,16 @@ void LLGLTFMaterial::writeToTexture(tinygltf::Model& model, T& texture_info, Tex ...@@ -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); 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 // static
void LLGLTFMaterial::hackOverrideUUID(LLUUID& id) void LLGLTFMaterial::hackOverrideUUID(LLUUID& id)
{ {
......
...@@ -71,6 +71,8 @@ class LLGLTFMaterial : public LLRefCount ...@@ -71,6 +71,8 @@ class LLGLTFMaterial : public LLRefCount
LLGLTFMaterial(const LLGLTFMaterial& rhs); LLGLTFMaterial(const LLGLTFMaterial& rhs);
LLGLTFMaterial& operator=(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 mBaseColorId;
LLUUID mNormalId; LLUUID mNormalId;
...@@ -101,7 +103,6 @@ class LLGLTFMaterial : public LLRefCount ...@@ -101,7 +103,6 @@ class LLGLTFMaterial : public LLRefCount
md5.finalize(); md5.finalize();
LLUUID id; LLUUID id;
md5.raw_digest(id.mData); md5.raw_digest(id.mData);
// *TODO: Hash the overrides
return id; return id;
} }
...@@ -181,6 +182,10 @@ class LLGLTFMaterial : public LLRefCount ...@@ -181,6 +182,10 @@ class LLGLTFMaterial : public LLRefCount
void applyOverride(const LLGLTFMaterial& override_mat); void applyOverride(const LLGLTFMaterial& override_mat);
// For material overrides only. Clears most properties to
// default/fallthrough, but preserves the transforms.
bool setBaseMaterial();
private: private:
template<typename T> template<typename T>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment