SL-18444 Live Material Editor updating with selection

master
Andrey Kleshchev 2022-10-26 00:41:35 +03:00
parent ca53f265b4
commit 89625f9247
5 changed files with 87 additions and 34 deletions

View File

@ -116,6 +116,7 @@ private:
viewer_media_t mMediaImpl;
LLMediaEntry* mMediaEntry;
LLSafeHandle<LLObjectSelection> mObjectSelection;
boost::signals2::connection mSelectionUpdateSlot;
};
LLInspectObject::LLInspectObject(const LLSD& sd)
@ -175,9 +176,12 @@ BOOL LLInspectObject::postBuild(void)
getChild<LLUICtrl>("more_info_btn")->setCommitCallback(
boost::bind(&LLInspectObject::onClickMoreInfo, this));
// Watch for updates to selection properties off the network
LLSelectMgr::getInstance()->mUpdateSignal.connect(
boost::bind(&LLInspectObject::update, this) );
if (!mSelectionUpdateSlot.connected())
{
// Watch for updates to selection properties off the network
mSelectionUpdateSlot = LLSelectMgr::getInstance()->mUpdateSignal.connect(
boost::bind(&LLInspectObject::update, this));
}
return TRUE;
}
@ -243,6 +247,11 @@ void LLInspectObject::onClose(bool app_quitting)
mObjectSelection = NULL;
mPreviousObjectID = mObjectID;
if (mSelectionUpdateSlot.connected())
{
mSelectionUpdateSlot.disconnect();
}
getChild<LLMenuButton>("gear_btn")->hideMenu();
}

View File

@ -302,6 +302,11 @@ void LLMaterialEditor::onClickCloseBtn(bool app_quitting)
void LLMaterialEditor::onClose(bool app_quitting)
{
if (mSelectionUpdateSlot.connected())
{
mSelectionUpdateSlot.disconnect();
}
LLPreview::onClose(app_quitting);
}
@ -1463,42 +1468,61 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
);
}
}
void LLMaterialEditor::onSelectionChanged()
{
mHasUnsavedChanges = false;
clearTextures();
setFromSelection();
saveLiveValues();
}
void LLMaterialEditor::saveLiveValues()
{
// Collect ids to be able to revert overrides.
// TODO: monitor selection changes and resave on selection changes
mObjectOverridesSavedValues.clear();
struct g : public LLSelectedObjectFunctor
{
g(LLMaterialEditor* me) : mEditor(me) {}
virtual bool apply(LLViewerObject* objectp)
{
if (!objectp)
{
return false;
}
U32 local_id = objectp->getLocalID();
S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces());
for (U8 te = 0; te < num_tes; te++)
{
LLUUID mat_id = objectp->getRenderMaterialID(te);
mEditor->mObjectOverridesSavedValues[local_id].push_back(mat_id);
}
return true;
}
LLMaterialEditor* mEditor;
} savefunc(this);
LLSelectMgr::getInstance()->getSelection()->applyToObjects(&savefunc);
}
void LLMaterialEditor::loadLive()
{
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor", LLSD(LIVE_MATERIAL_EDITOR_KEY));
if (me->setFromSelection())
if (me)
{
me->setFromSelection();
me->mIsOverride = true;
me->setTitle(me->getString("material_override_title"));
me->childSetVisible("save", false);
me->childSetVisible("save_as", false);
me->mObjectOverridesSavedValues.clear();
// Collect ids to be able to revert overrides.
// TODO: monitor selection changes and resave on selection changes
struct g : public LLSelectedObjectFunctor
// Set up for selection changes updates
if (!me->mSelectionUpdateSlot.connected())
{
g(LLMaterialEditor* me) : mEditor(me) {}
virtual bool apply(LLViewerObject* objectp)
{
if (!objectp)
{
return false;
}
U32 local_id = objectp->getLocalID();
S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces());
for (U8 te = 0; te < num_tes; te++)
{
LLUUID mat_id = objectp->getRenderMaterialID(te);
mEditor->mObjectOverridesSavedValues[local_id].push_back(mat_id);
}
return true;
}
LLMaterialEditor* mEditor;
} savefunc(me);
LLSelectMgr::getInstance()->getSelection()->applyToObjects(&savefunc);
me->mSelectionUpdateSlot = LLSelectMgr::instance().mUpdateSignal.connect(boost::bind(&LLMaterialEditor::onSelectionChanged, me));
}
// Collect ids to be able to revert overrides on cancel.
me->saveLiveValues();
me->openFloater();
me->setFocus(TRUE);
@ -2095,6 +2119,10 @@ bool LLMaterialEditor::setFromSelection()
return true;
}
// pick defaults from a blank material;
LLGLTFMaterial blank_mat;
setFromGLTFMaterial(&blank_mat);
return false;
}
@ -2424,6 +2452,16 @@ S32 LLMaterialEditor::saveTextures()
}
// discard upload buffers once textures have been saved
clearTextures();
// asset storage can callback immediately, causing a decrease
// of mUploadingTexturesCount, report amount of work scheduled
// not amount of work remaining
return work_count;
}
void LLMaterialEditor::clearTextures()
{
mBaseColorJ2C = nullptr;
mNormalJ2C = nullptr;
mEmissiveJ2C = nullptr;
@ -2438,11 +2476,6 @@ S32 LLMaterialEditor::saveTextures()
mNormalTextureUploadId.setNull();
mMetallicTextureUploadId.setNull();
mEmissiveTextureUploadId.setNull();
// asset storage can callback immediately, causing a decrease
// of mUploadingTexturesCount, report amount of work scheduled
// not amount of work remaining
return work_count;
}
void LLMaterialEditor::loadDefaults()

View File

@ -103,6 +103,8 @@ public:
// will promt to select specific one
static void loadMaterialFromFile(const std::string& filename, S32 index = -1);
void onSelectionChanged(); // // live overrides selection changes
void saveLiveValues(); // for restoration on cancel
static void loadLive();
static void loadObjectSave();
@ -118,6 +120,7 @@ public:
// save textures to inventory if needed
// returns amount of scheduled uploads
S32 saveTextures();
void clearTextures();
void onClickSave();
@ -279,5 +282,6 @@ private:
// local id, texture ids per face for object overrides
// for "cancel" support
std::map<U32, uuid_vec_t> mObjectOverridesSavedValues;
boost::signals2::connection mSelectionUpdateSlot;
};

View File

@ -77,7 +77,7 @@ static LLPanelInjector<LLSidepanelTaskInfo> t_task_info("sidepanel_task_info");
LLSidepanelTaskInfo::LLSidepanelTaskInfo()
{
setMouseOpaque(FALSE);
LLSelectMgr::instance().mUpdateSignal.connect(boost::bind(&LLSidepanelTaskInfo::refreshAll, this));
mSelectionUpdateSlot = LLSelectMgr::instance().mUpdateSignal.connect(boost::bind(&LLSidepanelTaskInfo::refreshAll, this));
}
@ -85,6 +85,11 @@ LLSidepanelTaskInfo::~LLSidepanelTaskInfo()
{
if (sActivePanel == this)
sActivePanel = NULL;
if (mSelectionUpdateSlot.connected())
{
mSelectionUpdateSlot.disconnect();
}
}
// virtual

View File

@ -154,6 +154,8 @@ private:
LLView* mDAE;
LLView* mDAN;
LLView* mDAF;
boost::signals2::connection mSelectionUpdateSlot;
};