From e70cf8edfee32d62392008fcba8ea5e7c0dd112f Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 27 Oct 2022 22:45:24 +0300 Subject: SL-18446 Live editing material should not override objects without pbr Objects without pbr have no base to override --- indra/newview/llmaterialeditor.cpp | 132 +++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 28 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 7ffa767e37..6fee65201d 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -67,7 +67,6 @@ const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive"; // Don't use ids here, LLPreview will attempt to use it as an inventory item static const std::string LIVE_MATERIAL_EDITOR_KEY = "Live Editor"; -static const std::string SAVE_LIVE_MATERIAL_KEY = "Save Material Editor"; // Dirty flags static const U32 MATERIAL_BASE_COLOR_DIRTY = 0x1 << 0; @@ -1507,10 +1506,12 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind } void LLMaterialEditor::onSelectionChanged() { + // This won't get deletion or deselectAll() + // Might need to handle that separately mUnsavedChanges = 0; clearTextures(); setFromSelection(); - saveLiveValues(); + // saveLiveValues(); todo } void LLMaterialEditor::saveLiveValues() @@ -1532,6 +1533,8 @@ void LLMaterialEditor::saveLiveValues() S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces()); for (U8 te = 0; te < num_tes; te++) { + // Todo: fix this, overrides don't care about ids, + // we will have to save actual values or materials LLUUID mat_id = objectp->getRenderMaterialID(te); mEditor->mObjectOverridesSavedValues[local_id].push_back(mat_id); } @@ -1544,6 +1547,7 @@ void LLMaterialEditor::saveLiveValues() void LLMaterialEditor::loadLive() { + // Allow only one 'live' instance const LLSD floater_key(LIVE_MATERIAL_EDITOR_KEY); LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", floater_key); if (me) @@ -1569,13 +1573,14 @@ void LLMaterialEditor::loadLive() void LLMaterialEditor::loadObjectSave() { - const LLSD floater_key(SAVE_LIVE_MATERIAL_KEY); - LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", floater_key); + LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); if (me && me->setFromSelection()) { me->mIsOverride = false; me->childSetVisible("save", false); - me->openFloater(floater_key); + me->mMaterialName = LLTrans::getString("New Material"); + me->setTitle(me->mMaterialName); + me->openFloater(); me->setFocus(TRUE); } } @@ -2053,13 +2058,15 @@ public: if (material.isNull()) { - material = new LLGLTFMaterial(); - } - else - { - material = new LLGLTFMaterial(*material); + // overrides are not supposed to work or apply if + // there is no base material to work from + return false; } + // make a copy to not invalidate existing + // material for multiple objects + material = new LLGLTFMaterial(*material); + // Override object's values with values from editor where appropriate if (mEditor->getUnsavedChangesFlags() & MATERIAL_BASE_COLOR_DIRTY) { @@ -2206,45 +2213,114 @@ void LLMaterialEditor::setFromGLTFMaterial(LLGLTFMaterial* mat) bool LLMaterialEditor::setFromSelection() { - struct LLSelectedTEGetGLTFRenderMaterial : public LLSelectedTEGetFunctor > + struct LLSelectedTEGetmatIdAndPermissions : public LLSelectedTEFunctor { - LLPointer get(LLViewerObject* objectp, S32 te_index) + LLSelectedTEGetmatIdAndPermissions(bool for_override) + : mIsOverride(for_override) + , mIdenticalTexColor(true) + , mIdenticalTexMetal(true) + , mIdenticalTexEmissive(true) + , mIdenticalTexNormal(true) + , mFirst(true) + {} + + bool apply(LLViewerObject* objectp, S32 te_index) { if (!objectp) { - return nullptr; + return false; } + LLUUID mat_id = objectp->getRenderMaterialID(te_index); + bool can_use = mIsOverride ? objectp->permModify() : objectp->permCopy(); LLTextureEntry *tep = objectp->getTE(te_index); - if (!tep) + // We might want to disable this entirely if at least + // something in selection is no-copy or no modify + // or has no base material + if (can_use && tep && mat_id.notNull()) { - return nullptr; + LLPointer mat = tep->getGLTFRenderMaterial(); + LLUUID tex_color_id; + LLUUID tex_metal_id; + LLUUID tex_emissive_id; + LLUUID tex_normal_id; + llassert(mat.notNull()); // by this point shouldn't be null + if (mat.notNull()) + { + tex_color_id = mat->mBaseColorId; + tex_metal_id = mat->mMetallicRoughnessId; + tex_emissive_id = mat->mEmissiveId; + tex_normal_id = mat->mNormalId; + } + if (mFirst) + { + mMaterial = mat; + mTexColorId = tex_color_id; + mTexMetalId = tex_metal_id; + mTexEmissiveId = tex_emissive_id; + mTexNormalId = tex_normal_id; + mFirst = false; + } + else + { + if (mTexColorId != tex_color_id) + { + mIdenticalTexColor = false; + } + if (mTexMetalId != tex_metal_id) + { + mIdenticalTexMetal = false; + } + if (mTexEmissiveId != tex_emissive_id) + { + mIdenticalTexEmissive = false; + } + if (mTexNormalId != tex_normal_id) + { + mIdenticalTexNormal = false; + } + } } - return tep->getGLTFRenderMaterial(); // present user with combined override + asset + return true; } - } func; - - LLPointer mat; - bool identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat); - if (mat.notNull()) - { - setFromGLTFMaterial(mat); + bool mIsOverride; + bool mIdenticalTexColor; + bool mIdenticalTexMetal; + bool mIdenticalTexEmissive; + bool mIdenticalTexNormal; + bool mFirst; + LLUUID mTexColorId; + LLUUID mTexMetalId; + LLUUID mTexEmissiveId; + LLUUID mTexNormalId; + LLPointer mMaterial; + } func(mIsOverride); + + LLSelectMgr::getInstance()->getSelection()->applyToTEs(&func); + if (func.mMaterial.notNull()) + { + setFromGLTFMaterial(func.mMaterial); + setEnableEditing(true); } else { // pick defaults from a blank material; LLGLTFMaterial blank_mat; setFromGLTFMaterial(&blank_mat); + if (mIsOverride) + { + setEnableEditing(false); + } } if (mIsOverride) { - mBaseColorTextureCtrl->setTentative(!identical); - mMetallicTextureCtrl->setTentative(!identical); - mEmissiveTextureCtrl->setTentative(!identical); - mNormalTextureCtrl->setTentative(!identical); + mBaseColorTextureCtrl->setTentative(!func.mIdenticalTexColor); + mMetallicTextureCtrl->setTentative(!func.mIdenticalTexMetal); + mEmissiveTextureCtrl->setTentative(!func.mIdenticalTexEmissive); + mNormalTextureCtrl->setTentative(!func.mIdenticalTexNormal); } - return mat.notNull(); + return func.mMaterial.notNull(); } -- cgit v1.3 From 29062fd90763d6865db514cfc6c012c08f9621e5 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 27 Oct 2022 23:06:12 +0300 Subject: SL-18441 "Override" UI cleanup --- indra/newview/llmaterialeditor.cpp | 9 +++++---- indra/newview/skins/default/xui/en/floater_material_editor.xml | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 6fee65201d..a8b0fdb3c9 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -227,6 +227,8 @@ LLMaterialEditor::LLMaterialEditor(const LLSD& key) { mAssetID = item->getAssetUUID(); } + // if this is a 'live editor' instance, it uses live overrides + mIsOverride = key.asString() == LIVE_MATERIAL_EDITOR_KEY; } void LLMaterialEditor::setObjectID(const LLUUID& object_id) @@ -293,7 +295,7 @@ BOOL LLMaterialEditor::postBuild() // Emissive childSetCommitCallback("emissive color", changes_callback, (void*)&MATERIAL_EMISIVE_COLOR_DIRTY); - childSetVisible("unsaved_changes", mUnsavedChanges); + childSetVisible("unsaved_changes", mUnsavedChanges && !mIsOverride); getChild("total_upload_fee")->setTextArg("[FEE]", llformat("%d", 0)); @@ -527,7 +529,8 @@ void LLMaterialEditor::resetUnsavedChanges() void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag) { mUnsavedChanges |= dirty_flag; - childSetVisible("unsaved_changes", mUnsavedChanges); + // at the moment live editing (mIsOverride) applies everything 'live' + childSetVisible("unsaved_changes", mUnsavedChanges && !mIsOverride); if (mUnsavedChanges) { @@ -1552,7 +1555,6 @@ void LLMaterialEditor::loadLive() LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", floater_key); if (me) { - me->mIsOverride = true; me->setFromSelection(); me->setTitle(me->getString("material_override_title")); me->childSetVisible("save", false); @@ -1576,7 +1578,6 @@ void LLMaterialEditor::loadObjectSave() LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); if (me && me->setFromSelection()) { - me->mIsOverride = false; me->childSetVisible("save", false); me->mMaterialName = LLTrans::getString("New Material"); me->setTitle(me->mMaterialName); diff --git a/indra/newview/skins/default/xui/en/floater_material_editor.xml b/indra/newview/skins/default/xui/en/floater_material_editor.xml index 434123faf0..84264cd2e6 100644 --- a/indra/newview/skins/default/xui/en/floater_material_editor.xml +++ b/indra/newview/skins/default/xui/en/floater_material_editor.xml @@ -15,7 +15,7 @@ L$[FEE] upload fee Material selection Select material: - Material override + Editing Material - Usaved changes + Unsaved changes