diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2023-10-30 23:56:33 +0200 |
---|---|---|
committer | akleshchev <117672381+akleshchev@users.noreply.github.com> | 2023-11-06 18:29:42 +0200 |
commit | 3a5b678eba5d86acccb1a1f233f862d292258fac (patch) | |
tree | 16c71f0ed33daa46c9c10281255ec0a37dca7749 | |
parent | 596a63051ebabfec51e48be02bbec33ab962d915 (diff) |
SL-20523 Local textures not updating on PBR Materials #3
-rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 9 | ||||
-rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 5 | ||||
-rw-r--r-- | indra/newview/lllocalbitmaps.cpp | 26 | ||||
-rw-r--r-- | indra/newview/llmaterialeditor.cpp | 58 |
4 files changed, 68 insertions, 30 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index 6afd83904f..e590b14656 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -770,6 +770,15 @@ LLUUID LLGLTFMaterial::getHash() const return hash; } +void LLGLTFMaterial::addTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.insert(te); +} +void LLGLTFMaterial::removeTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.erase(te); +} + void LLGLTFMaterial::addLocalTextureTracking(const LLUUID& tracking_id, const LLUUID& tex_id) { mLocalTextureTrackingIds.insert(tracking_id); diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index d45ada1561..2a9ef3ffe0 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -219,8 +219,8 @@ public: // For local materials, they have to keep track of where // they are assigned to for full updates - virtual void addTextureEntry(LLTextureEntry* te) {}; - virtual void removeTextureEntry(LLTextureEntry* te) {}; + virtual void addTextureEntry(LLTextureEntry* te); + virtual void removeTextureEntry(LLTextureEntry* te); // For local textures so that editor will know to track changes void addLocalTextureTracking(const LLUUID& tracking_id, const LLUUID &tex_id); @@ -231,6 +231,7 @@ public: uuid_set_t mLocalTextureIds; uuid_set_t mLocalTextureTrackingIds; + std::set<LLTextureEntry*> mTextureEntires; protected: static LLVector2 vec2FromJson(const std::map<std::string, tinygltf::Value>& object, const char* key, const LLVector2& default_value); diff --git a/indra/newview/lllocalbitmaps.cpp b/indra/newview/lllocalbitmaps.cpp index 88de575f91..6775685a6a 100644 --- a/indra/newview/lllocalbitmaps.cpp +++ b/indra/newview/lllocalbitmaps.cpp @@ -614,6 +614,30 @@ void LLLocalBitmap::updateGLTFMaterials(LLUUID old_id, LLUUID new_id) { if ((*it)->replaceLocalTexture(old_id, new_id)) { + for (LLTextureEntry* entry : (*it)->mTextureEntires) + { + // Normally a change in applied material id is supposed to + // drop overrides thus reset material, but local materials + // currently reuse their existing asset id, and purpose is + // to preview how material will work in-world, overrides + // included, so do an override to render update instead. + LLGLTFMaterial* override_mat = entry->getGLTFMaterialOverride(); + if (override_mat) + { + // do not create a new material, reuse existing pointer + LLFetchedGLTFMaterial* render_mat = (LLFetchedGLTFMaterial*)entry->getGLTFRenderMaterial(); + if (render_mat) + { + llassert(dynamic_cast<LLFetchedGLTFMaterial*>(entry->getGLTFRenderMaterial()) != nullptr); + LLFetchedGLTFMaterial *fetched_mat = dynamic_cast<LLFetchedGLTFMaterial*>((*it).get()); + if (fetched_mat) + { + *render_mat = *fetched_mat; + } + render_mat->applyOverride(*override_mat); + } + } + } ++it; } else @@ -1119,7 +1143,7 @@ boost::signals2::connection LLLocalBitmapMgr::setOnChangedCallback(const LLUUID LLLocalBitmap* unit = *iter; if (unit->getTrackingID() == tracking_id) { - unit->setChangedCallback(cb); + return unit->setChangedCallback(cb); } } diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index b8e34b7409..836ea5c869 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -365,11 +365,6 @@ LLMaterialEditor::LLMaterialEditor(const LLSD& key) LLMaterialEditor::~LLMaterialEditor() { - for (mat_connection_map_t::value_type cn : mTextureChangesUpdates) - { - cn.second.mConnection.disconnect(); - } - mTextureChangesUpdates.clear(); } void LLMaterialEditor::setObjectID(const LLUUID& object_id) @@ -540,6 +535,11 @@ void LLMaterialEditor::onClose(bool app_quitting) { mSelectionUpdateSlot.disconnect(); } + for (mat_connection_map_t::value_type cn : mTextureChangesUpdates) + { + cn.second.mConnection.disconnect(); + } + mTextureChangesUpdates.clear(); LLPreview::onClose(app_quitting); } @@ -872,22 +872,24 @@ void LLMaterialEditor::setEnableEditing(bool can_modify) void LLMaterialEditor::subscribeToLocalTexture(S32 dirty_flag, const LLUUID& tracking_id) { - LocalTextureConnection info; - info.mTrackingId = tracking_id; - info.mConnection = LLLocalBitmapMgr::getInstance()->setOnChangedCallback(tracking_id, - [this, dirty_flag](const LLUUID& tracking_id, const LLUUID& old_id, const LLUUID& new_id) - { - if (new_id.isNull()) - { - mTextureChangesUpdates[dirty_flag].mConnection.disconnect(); - mTextureChangesUpdates.erase(dirty_flag); - } - else - { - replaceLocalTexture(old_id, new_id); - } - }); - mTextureChangesUpdates[dirty_flag] = info; + if (mTextureChangesUpdates[dirty_flag].mTrackingId != tracking_id) + { + mTextureChangesUpdates[dirty_flag].mConnection.disconnect(); + mTextureChangesUpdates[dirty_flag].mTrackingId = tracking_id; + mTextureChangesUpdates[dirty_flag].mConnection = LLLocalBitmapMgr::getInstance()->setOnChangedCallback(tracking_id, + [this, dirty_flag](const LLUUID& tracking_id, const LLUUID& old_id, const LLUUID& new_id) + { + if (new_id.isNull()) + { + mTextureChangesUpdates[dirty_flag].mConnection.disconnect(); + //mTextureChangesUpdates.erase(dirty_flag); + } + else + { + replaceLocalTexture(old_id, new_id); + } + }); + } } void LLMaterialEditor::replaceLocalTexture(const LLUUID& old_id, const LLUUID& new_id) @@ -981,19 +983,21 @@ void LLMaterialEditor::onCommitTexture(LLUICtrl* ctrl, const LLSD& data, S32 dir // the texture that is not in use childSetValue(upload_fee_ctrl_name, getString("no_upload_fee_string")); } + } + LLTextureCtrl* tex_ctrl = (LLTextureCtrl*)ctrl; + if (tex_ctrl->isImageLocal()) + { + subscribeToLocalTexture(dirty_flag, tex_ctrl->getLocalTrackingID()); + } + else + { // unsubcribe potential old callabck mat_connection_map_t::iterator found = mTextureChangesUpdates.find(dirty_flag); if (found != mTextureChangesUpdates.end()) { found->second.mConnection.disconnect(); } - - LLTextureCtrl* tex_ctrl = (LLTextureCtrl*)ctrl; - if (tex_ctrl->isImageLocal()) - { - subscribeToLocalTexture(dirty_flag, tex_ctrl->getLocalTrackingID()); - } } markChangesUnsaved(dirty_flag); |