diff options
| author | cosmic-linden <111533034+cosmic-linden@users.noreply.github.com> | 2023-01-11 10:36:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-11 10:36:35 -0800 |
| commit | 7e1f4e4cc7588131e12b3fc7542e10d066aad93f (patch) | |
| tree | d1abc294fe0a7508d6d3b9d0b6661694b11719d9 /indra/llprimitive | |
| parent | b4f53334141b179bdb1762636ce313f14d9e2b10 (diff) | |
| parent | 693925ef23ef41e3927a9654a7f423d0e24ce19a (diff) | |
Merge pull request #48 from secondlife/SL-18820
Sl 18820: Build floater should preserve GLTF transforms when changing the PBR material
Diffstat (limited to 'indra/llprimitive')
| -rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 45 | ||||
| -rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 11 | ||||
| -rw-r--r-- | indra/llprimitive/lltextureentry.cpp | 29 | ||||
| -rw-r--r-- | indra/llprimitive/lltextureentry.h | 6 |
4 files changed, 85 insertions, 6 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index c98fd7d1ee..a8dad89292 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,28 @@ 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; + setBaseMaterial(old_override); + return *this != old_override; +} + +bool LLGLTFMaterial::isClearedForBaseMaterial() +{ + LLGLTFMaterial cleared_override = sDefault; + cleared_override.setBaseMaterial(*this); + return *this == cleared_override; +} + +// For material overrides only. Copies transforms from the old override. +void LLGLTFMaterial::setBaseMaterial(const LLGLTFMaterial& old_override_mat) +{ + mTextureTransform = old_override_mat.mTextureTransform; +} + + // static void LLGLTFMaterial::hackOverrideUUID(LLUUID& id) { diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index aa49a58f0c..dec7b696f8 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -71,6 +71,8 @@ public: 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 @@ public: md5.finalize(); LLUUID id; md5.raw_digest(id.mData); - // *TODO: Hash the overrides return id; } @@ -181,6 +182,12 @@ public: void applyOverride(const LLGLTFMaterial& override_mat); + // For material overrides only. Clears most properties to + // default/fallthrough, but preserves the transforms. + bool setBaseMaterial(); + // True if setBaseMaterial() was just called + bool isClearedForBaseMaterial(); + private: template<typename T> @@ -188,5 +195,7 @@ private: template<typename T> void writeToTexture(tinygltf::Model& model, T& texture_info, TextureInfo texture_info_id, const LLUUID& texture_id) const; + + void setBaseMaterial(const LLGLTFMaterial& old_override_mat); }; diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp index a0d5793dcc..49f67918f8 100644 --- a/indra/llprimitive/lltextureentry.cpp +++ b/indra/llprimitive/lltextureentry.cpp @@ -514,15 +514,15 @@ S32 LLTextureEntry::setBumpShiny(U8 bump_shiny) return TEM_CHANGE_NONE; } -void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material) +void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material, bool local_origin) { if (material != getGLTFMaterial()) { // assert on precondtion: - // whether or not mGLTFMaterial is null, any existing override should have been nulled out + // whether or not mGLTFMaterial is null, any existing override should have been cleared // before calling setGLTFMaterial // NOTE: if you're hitting this assert, try to make sure calling code is using LLViewerObject::setRenderMaterialID - llassert(getGLTFMaterialOverride() == nullptr); + llassert(!local_origin || getGLTFMaterialOverride() == nullptr || getGLTFMaterialOverride()->isClearedForBaseMaterial()); mGLTFMaterial = material; if (mGLTFMaterial == nullptr) @@ -538,6 +538,27 @@ void LLTextureEntry::setGLTFMaterialOverride(LLGLTFMaterial* mat) mGLTFMaterialOverrides = mat; } +S32 LLTextureEntry::setBaseMaterial() +{ + S32 changed = TEM_CHANGE_NONE; + + if (mGLTFMaterialOverrides) + { + if (mGLTFMaterialOverrides->setBaseMaterial()) + { + changed = TEM_CHANGE_TEXTURE; + } + + if (LLGLTFMaterial::sDefault == *mGLTFMaterialOverrides) + { + mGLTFMaterialOverrides = nullptr; + changed = TEM_CHANGE_TEXTURE; + } + } + + return changed; +} + LLGLTFMaterial* LLTextureEntry::getGLTFRenderMaterial() const { if (mGLTFRenderMaterial.notNull()) @@ -545,7 +566,7 @@ LLGLTFMaterial* LLTextureEntry::getGLTFRenderMaterial() const return mGLTFRenderMaterial; } - llassert(getGLTFMaterialOverride() == nullptr); + llassert(getGLTFMaterialOverride() == nullptr || getGLTFMaterialOverride()->isClearedForBaseMaterial()); return getGLTFMaterial(); } diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index d94e14bd73..9a81181f3a 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -195,12 +195,16 @@ public: enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 }; // GLTF asset - void setGLTFMaterial(LLGLTFMaterial* material); + void setGLTFMaterial(LLGLTFMaterial* material, bool local_origin = true); LLGLTFMaterial* getGLTFMaterial() const { return mGLTFMaterial; } // GLTF override LLGLTFMaterial* getGLTFMaterialOverride() const { return mGLTFMaterialOverrides; } void setGLTFMaterialOverride(LLGLTFMaterial* mat); + // Clear most overrides so the render material better matches the material + // ID (preserve transforms). If the overrides become passthrough, set the + // overrides to nullptr. + S32 setBaseMaterial(); // GLTF render material // nuanced behavior here -- if there is no render material, fall back to getGLTFMaterial, but ONLY for the getter, not the setter |
