SL-18523: When editing an object's material override, use the object's material override as a base, rather than its render material

meow-7.2.2
Cosmic Linden 2022-11-08 10:53:24 -08:00
parent d72824c2b7
commit cba87c62cc
3 changed files with 40 additions and 4 deletions

View File

@ -61,6 +61,29 @@ LLMatrix3 LLGLTFMaterial::TextureTransform::asMatrix()
return offset * rotation * scale;
}
LLGLTFMaterial::LLGLTFMaterial(bool for_override)
: LLGLTFMaterial()
{
if (for_override)
{
setBaseColorId(mBaseColorId, for_override);
setNormalId(mNormalId, for_override);
setMetallicRoughnessId(mMetallicRoughnessId, for_override);
setEmissiveId(mEmissiveId, for_override);
setBaseColorFactor(mBaseColor, for_override);
setAlphaCutoff(mAlphaCutoff, for_override);
setEmissiveColorFactor(mEmissiveColor, for_override);
setMetallicFactor(mMetallicFactor, for_override);
setRoughnessFactor(mRoughnessFactor, for_override);
setAlphaMode(mAlphaMode, for_override);
setDoubleSided(mDoubleSided, for_override);
// *NOTE: Texture offsets only exist in overrides, so there is no need
// to hack in the override value here.
}
}
LLGLTFMaterial::LLGLTFMaterial(const LLGLTFMaterial& rhs)
{
*this = rhs;
@ -588,6 +611,9 @@ void LLGLTFMaterial::applyOverrideUUID(LLUUID& dst_id, const LLUUID& override_id
}
}
// Make a static default material override for editing materials
const LLGLTFMaterial LLGLTFMaterial::sOverrideDefault{true};
void LLGLTFMaterial::applyOverride(const LLGLTFMaterial& override_mat)
{
LL_PROFILE_ZONE_SCOPED;

View File

@ -48,6 +48,8 @@ public:
// default material for reference
static const LLGLTFMaterial sDefault;
// default material override for reference
static const LLGLTFMaterial sOverrideDefault;
struct TextureTransform
{
@ -66,6 +68,7 @@ public:
};
LLGLTFMaterial() {}
LLGLTFMaterial(bool for_override);
LLGLTFMaterial(const LLGLTFMaterial& rhs);
LLGLTFMaterial& operator=(const LLGLTFMaterial& rhs);

View File

@ -2385,19 +2385,26 @@ public:
// Selection can cover multiple objects, and live editor is
// supposed to overwrite changed values only
LLTextureEntry* tep = objectp->getTE(te);
LLPointer<LLGLTFMaterial> material = tep->getGLTFRenderMaterial();
if (material.isNull())
if (tep->getGLTFMaterial().isNull())
{
// overrides are not supposed to work or apply if
// there is no base material to work from
return false;
}
LLPointer<LLGLTFMaterial> material = tep->getGLTFMaterialOverride();
// make a copy to not invalidate existing
// material for multiple objects
material = new LLGLTFMaterial(*material);
if (material.isNull())
{
// Start with a material override which does not make any changes
material = new LLGLTFMaterial(LLGLTFMaterial::sOverrideDefault);
}
else
{
material = new LLGLTFMaterial(*material);
}
U32 changed_flags = mEditor->getUnsavedChangesFlags();
U32 reverted_flags = mEditor->getRevertedChangesFlags();