From 49278013ef3af18f4565f46aeb67368e6439ae46 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 8 Aug 2022 23:24:29 +0300 Subject: SL-17653 Apply selection to faces and linkset instead of just first object --- indra/newview/llmaterialeditor.cpp | 52 +++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 57cd74e0f2..0e252518cb 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -62,6 +62,7 @@ const std::string MATERIAL_NORMAL_DEFAULT_NAME = "Normal"; const std::string MATERIAL_METALLIC_DEFAULT_NAME = "Metallic Roughness"; const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive"; + class LLMaterialEditorCopiedCallback : public LLInventoryCallback { public: @@ -1341,34 +1342,39 @@ void LLMaterialEditor::importMaterial() (new LLMaterialFilePicker(this))->getFile(); } -void LLMaterialEditor::applyToSelection() +class LLRemderMaterialFunctor : public LLSelectedTEFunctor { - // Todo: fix this, this is a hack, not a proper live preview - LLViewerObject* objectp = LLSelectMgr::instance().getSelection()->getFirstObject(); - if (objectp && objectp->getVolume() && objectp->permModify()) +public: + LLRemderMaterialFunctor(LLGLTFMaterial *mat, const LLUUID &id) + : mMat(mat), mMatId(id) { - LLGLTFMaterial* mat = new LLGLTFMaterial(); - getGLTFMaterial(mat); - LLVOVolume* vobjp = (LLVOVolume*)objectp; - for (int i = 0; i < vobjp->getNumTEs(); ++i) - { - // this is here just to prevent material from immediately resetting - if (mAssetID.notNull()) - { - vobjp->setRenderMaterialID(i, mAssetID); - } - else - { - const LLUUID placeholder("984e183e-7811-4b05-a502-d79c6f978a98"); - vobjp->setRenderMaterialID(i, placeholder); - } + } - vobjp->getTE(i)->setGLTFMaterial(mat); - vobjp->updateTEMaterialTextures(i); + virtual bool apply(LLViewerObject* objectp, S32 te) + { + if (objectp && objectp->permModify() && objectp->getVolume()) + { + LLVOVolume* vobjp = (LLVOVolume*)objectp; + vobjp->setRenderMaterialID(te, mMatId); + vobjp->getTE(te)->setGLTFMaterial(mMat); + vobjp->updateTEMaterialTextures(te); } - - vobjp->markForUpdate(TRUE); + return true; } +private: + LLGLTFMaterial *mMat; + LLUUID mMatId; +}; + +void LLMaterialEditor::applyToSelection() +{ + LLGLTFMaterial* mat = new LLGLTFMaterial(); + getGLTFMaterial(mat); + const LLUUID placeholder("984e183e-7811-4b05-a502-d79c6f978a98"); + LLUUID asset_id = mAssetID.notNull() ? mAssetID : placeholder; + LLRemderMaterialFunctor mat_func(mat, mAssetID); + LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection(); + selected_objects->applyToTEs(&mat_func); } void LLMaterialEditor::getGLTFMaterial(LLGLTFMaterial* mat) -- cgit v1.3 From e73fd2a2f28a01c1ab1e0dee63ba4d2ca73c9634 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 9 Aug 2022 00:21:45 +0300 Subject: SL-17653 Perially done restoration functionality --- indra/newview/llmaterialeditor.cpp | 15 ++++++++--- indra/newview/llmaterialeditor.h | 2 ++ indra/newview/llselectmgr.cpp | 52 ++++++++++++++++++++++++++++++++++++++ indra/newview/llselectmgr.h | 3 +++ 4 files changed, 69 insertions(+), 3 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 0e252518cb..13e250ec3b 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -165,6 +165,15 @@ void LLMaterialEditor::onClickCloseBtn(bool app_quitting) } } +void LLMaterialEditor::onClose(bool app_quitting) +{ + // todo: will only revert whatever was recently selected, + // Later should work based of tools floater + LLSelectMgr::getInstance()->selectionRevertGLTFMaterials(); + + LLPreview::onClose(app_quitting); +} + LLUUID LLMaterialEditor::getAlbedoId() { return mAlbedoTextureCtrl->getValue().asUUID(); @@ -1362,17 +1371,17 @@ public: return true; } private: - LLGLTFMaterial *mMat; + LLPointer mMat; LLUUID mMatId; }; void LLMaterialEditor::applyToSelection() { - LLGLTFMaterial* mat = new LLGLTFMaterial(); + LLPointer mat = new LLGLTFMaterial(); getGLTFMaterial(mat); const LLUUID placeholder("984e183e-7811-4b05-a502-d79c6f978a98"); LLUUID asset_id = mAssetID.notNull() ? mAssetID : placeholder; - LLRemderMaterialFunctor mat_func(mat, mAssetID); + LLRemderMaterialFunctor mat_func(mat, asset_id); LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection(); selected_objects->applyToTEs(&mat_func); } diff --git a/indra/newview/llmaterialeditor.h b/indra/newview/llmaterialeditor.h index 3da59c7f93..1b81a7144a 100644 --- a/indra/newview/llmaterialeditor.h +++ b/indra/newview/llmaterialeditor.h @@ -103,6 +103,8 @@ public: BOOL postBuild() override; void onClickCloseBtn(bool app_quitting = false) override; + void onClose(bool app_quitting) override; + LLUUID getAlbedoId(); void setAlbedoId(const LLUUID& id); void setAlbedoUploadId(const LLUUID& id); diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 853703b4d5..fc5b1c60e2 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -1936,6 +1936,32 @@ BOOL LLSelectMgr::selectionRevertTextures() return revert_successful; } +void LLSelectMgr::selectionRevertGLTFMaterials() +{ + struct f : public LLSelectedTEFunctor + { + LLObjectSelectionHandle mSelectedObjects; + f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {} + bool apply(LLViewerObject* object, S32 te) + { + if (object->permModify()) + { + LLSelectNode* nodep = mSelectedObjects->findNode(object); + if (nodep && te < (S32)nodep->mSavedGLTFMaterials.size()) + { + LLUUID id = nodep->mSavedGLTFMaterials[te]; + object->setRenderMaterialID(te, id); + } + } + return true; + } + } setfunc(mSelectedObjects); + getSelection()->applyToTEs(&setfunc); + + LLSelectMgrSendFunctor sendfunc; + getSelection()->applyToObjects(&sendfunc); +} + void LLSelectMgr::selectionSetBumpmap(U8 bumpmap, const LLUUID &image_id) { struct f : public LLSelectedTEFunctor @@ -5526,6 +5552,17 @@ void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data // this should be the only place that saved textures is called node->saveTextures(texture_ids); } + + if (can_copy && can_transfer && node->getObject()->getVolume()) + { + uuid_vec_t material_ids; + LLVOVolume* vobjp = (LLVOVolume*)node->getObject(); + for (int i = 0; i < vobjp->getNumTEs(); ++i) + { + material_ids.push_back(vobjp->getRenderMaterialID(i)); + } + node->savedGLTFMaterials(material_ids); + } } node->mValid = TRUE; @@ -6277,6 +6314,7 @@ LLSelectNode::LLSelectNode(const LLSelectNode& nodep) } saveTextures(nodep.mSavedTextures); + savedGLTFMaterials(nodep.mSavedGLTFMaterials); } LLSelectNode::~LLSelectNode() @@ -6392,6 +6430,20 @@ void LLSelectNode::saveTextures(const uuid_vec_t& textures) } } +void LLSelectNode::savedGLTFMaterials(const uuid_vec_t& materials) +{ + if (mObject.notNull()) + { + mSavedGLTFMaterials.clear(); + + for (uuid_vec_t::const_iterator materials_it = materials.begin(); + materials_it != materials.end(); ++materials_it) + { + mSavedGLTFMaterials.push_back(*materials_it); + } + } +} + void LLSelectNode::saveTextureScaleRatios(LLRender::eTexIndex index_to_query) { mTextureScaleRatios.clear(); diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h index ce0316e610..aec2baa6a7 100644 --- a/indra/newview/llselectmgr.h +++ b/indra/newview/llselectmgr.h @@ -187,6 +187,7 @@ public: void saveColors(); void saveShinyColors(); void saveTextures(const uuid_vec_t& textures); + void savedGLTFMaterials(const uuid_vec_t& materials); void saveTextureScaleRatios(LLRender::eTexIndex index_to_query); BOOL allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const; @@ -224,6 +225,7 @@ public: std::vector mSavedColors; std::vector mSavedShinyColors; uuid_vec_t mSavedTextures; + uuid_vec_t mSavedGLTFMaterials; std::vector mTextureScaleRatios; std::vector mSilhouetteVertices; // array of vertices to render silhouette of object std::vector mSilhouetteNormals; // array of normals to render silhouette of object @@ -609,6 +611,7 @@ public: void selectionRevertColors(); void selectionRevertShinyColors(); BOOL selectionRevertTextures(); + void selectionRevertGLTFMaterials(); void selectionSetBumpmap( U8 bumpmap, const LLUUID &image_id ); void selectionSetTexGen( U8 texgen ); void selectionSetShiny( U8 shiny, const LLUUID &image_id ); -- cgit v1.3