SL-20523 Local textures not updating on PBR Materials #3

meow-7.2.2
Andrey Kleshchev 2023-10-30 23:56:33 +02:00 committed by akleshchev
parent 596a63051e
commit 3a5b678eba
4 changed files with 68 additions and 30 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);