From 0e60ec606a4f1888aa64d344cadb4d75a41717c3 Mon Sep 17 00:00:00 2001 From: Hecklezz Date: Mon, 19 May 2025 15:04:56 +1000 Subject: [PATCH] Improves GLTF hiding while object is displaying BP with updates from the server --- indra/newview/fspanelface.cpp | 2 +- indra/newview/llviewerobject.cpp | 112 +++++++++++++++++++++---------- indra/newview/llviewerobject.h | 1 + 3 files changed, 79 insertions(+), 36 deletions(-) diff --git a/indra/newview/fspanelface.cpp b/indra/newview/fspanelface.cpp index 8ff008372c..e041218009 100644 --- a/indra/newview/fspanelface.cpp +++ b/indra/newview/fspanelface.cpp @@ -737,7 +737,6 @@ void FSPanelFace::onMatTabChange() if(objectp) { last_mat = curr_mat; - gSavedSettings.setBOOL("FSShowSelectedInBlinnPhong", (curr_mat == MATMEDIA_MATERIAL)); // Iterate through the linkset and mark each object for update for (LLObjectSelection::iterator iter = LLSelectMgr::getInstance()->getSelection()->begin(); iter != LLSelectMgr::getInstance()->getSelection()->end(); ++iter) @@ -760,6 +759,7 @@ void FSPanelFace::onMatTabChange() // Since we allow both PBR and BP textures to be applied at the same time, // we need to hide or show the GLTF material only locally based on the current tab. + gSavedSettings.setBOOL("FSShowSelectedInBlinnPhong", (curr_mat == MATMEDIA_MATERIAL)); if (curr_mat != MATMEDIA_PBR) LLSelectMgr::getInstance()->hideGLTFMaterial(); else diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index 01b2f2aacb..9cc99b53d2 100644 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -7756,6 +7756,16 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat start_idx = llmax(start_idx, 0); end_idx = llmin(end_idx, (S32) getNumTEs()); + // [FIRE-35138] If we are hiding the GLTF material, call the function again but with a null material id + static LLCachedControl showSelectedinBP(gSavedSettings, "FSShowSelectedInBlinnPhong"); + bool hiding_gltf_material = showSelectedinBP && isSelected(); + if (hiding_gltf_material && id.notNull()) + { + setRenderMaterialID(te_in, LLUUID::null, update_server, local_origin); + return; + } + // + LLRenderMaterialParams* param_block = (LLRenderMaterialParams*)getParameterEntry(LLNetworkData::PARAMS_RENDER_MATERIAL); if (!param_block && id.notNull()) { // block doesn't exist, but it will need to @@ -7792,43 +7802,53 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat } } - if (update_server || material_changed) - { - tep->setGLTFRenderMaterial(nullptr); - } - - if (new_material != tep->getGLTFMaterial()) - { - tep->setGLTFMaterial(new_material, !update_server); - } - - if (material_changed && new_material) - { - // Sometimes, the material may change out from underneath the overrides. - // This is usually due to the server sending a new material ID, but - // the overrides have not changed due to being only texture - // transforms. Re-apply the overrides to the render material here, - // if present. - const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride(); - if (override_material) + // [FIRE-35138] Only set GLTF material if not hiding it + if (!hiding_gltf_material) + { // + if (update_server || material_changed) { - new_material->onMaterialComplete([obj_id = getID(), te]() - { - LLViewerObject* obj = gObjectList.findObject(obj_id); - if (!obj) { return; } - LLTextureEntry* tep = obj->getTE(te); - if (!tep) { return; } - const LLGLTFMaterial* new_material = tep->getGLTFMaterial(); - if (!new_material) { return; } - const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride(); - if (!override_material) { return; } - LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial(); - *render_material = *new_material; - render_material->applyOverride(*override_material); - tep->setGLTFRenderMaterial(render_material); - }); + tep->setGLTFRenderMaterial(nullptr); } - } + + if (new_material != tep->getGLTFMaterial()) + { + tep->setGLTFMaterial(new_material, !update_server); + } + + if (material_changed && new_material) + { + // Sometimes, the material may change out from underneath the overrides. + // This is usually due to the server sending a new material ID, but + // the overrides have not changed due to being only texture + // transforms. Re-apply the overrides to the render material here, + // if present. + const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride(); + if (override_material) + { + new_material->onMaterialComplete([obj_id = getID(), te]() + { + LLViewerObject* obj = gObjectList.findObject(obj_id); + if (!obj) { return; } + LLTextureEntry* tep = obj->getTE(te); + if (!tep) { return; } + const LLGLTFMaterial* new_material = tep->getGLTFMaterial(); + if (!new_material) { return; } + const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride(); + if (!override_material) { return; } + LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial(); + *render_material = *new_material; + render_material->applyOverride(*override_material); + tep->setGLTFRenderMaterial(render_material); + }); + } + } + + // [FIRE-35138] Update the saved GLTF material since we got an update + if (material_changed) + { + updateSavedGLTFMaterial(te); + } + } // } // signal to render pipe that render batches must be rebuilt for this object @@ -7907,6 +7927,28 @@ void LLViewerObject::saveGLTFMaterials() } } +void LLViewerObject::updateSavedGLTFMaterial(S32 te) +{ + if (te >= mSavedGLTFMaterialIds.size()) + { + // Nothing is saved, so don't need to update anything + return; + } + + mSavedGLTFMaterialIds[te] = getRenderMaterialID(te); + + LLPointer old_override = getTE(te)->getGLTFMaterialOverride(); + if (old_override.notNull()) + { + LLGLTFMaterial* copy = new LLGLTFMaterial(*old_override); + mSavedGLTFOverrideMaterials[te] = copy; + } + else + { + mSavedGLTFOverrideMaterials[te] = nullptr; + } +} + void LLViewerObject::clearSavedGLTFMaterials() { mSavedGLTFMaterialIds.clear(); diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index 9adfbd0c73..0544286636 100644 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -214,6 +214,7 @@ public: const uuid_vec_t& getSavedGLTFMaterialIds() const { return mSavedGLTFMaterialIds; }; const gltf_materials_vec_t& getSavedGLTFOverrideMaterials() const { return mSavedGLTFOverrideMaterials; }; void saveGLTFMaterials(); + void updateSavedGLTFMaterial(S32 te); void clearSavedGLTFMaterials(); //