diff options
-rw-r--r-- | indra/newview/llselectmgr.cpp | 80 | ||||
-rw-r--r-- | indra/newview/llselectmgr.h | 16 |
2 files changed, 87 insertions, 9 deletions
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 52b35d5158..fa9604ef9d 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -2215,10 +2215,31 @@ void LLSelectMgr::selectionRevertGLTFMaterials() } LLSelectNode* nodep = mSelectedObjects->findNode(objectp); - if (nodep && te < (S32)nodep->mSavedGLTFMaterials.size()) + if (nodep && te < (S32)nodep->mSavedGLTFMaterialIds.size()) { - LLUUID asset_id = nodep->mSavedGLTFMaterials[te]; + // Restore base material + LLUUID asset_id = nodep->mSavedGLTFMaterialIds[te]; objectp->setRenderMaterialID(te, asset_id, false /*wait for bulk update*/); + + // Restore overrides + LLSD overrides; + overrides["object_id"] = objectp->getID(); + overrides["side"] = te; + + // todo: make sure this does not cause race condition with setRenderMaterialID + // when we are reverting from null id to non null plus override + if (te < (S32)nodep->mSavedGLTFRenderMaterials.size() + && nodep->mSavedGLTFRenderMaterials[te].notNull() + && asset_id.notNull()) + { + overrides["gltf_json"] = nodep->mSavedGLTFRenderMaterials[te]->asJSON(); + } // else nothing to blank override out + + LLCoros::instance().launch("modifyMaterialCoro", + std::bind(&LLGLTFMaterialList::modifyMaterialCoro, + gAgent.getRegionCapability("ModifyMaterialParams"), + overrides, + nullptr)); } return true; } @@ -5848,12 +5869,33 @@ void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data if (can_copy && can_transfer && node->getObject()->getVolume()) { uuid_vec_t material_ids; + gltf_materials_vec_t materials; LLVOVolume* vobjp = (LLVOVolume*)node->getObject(); for (int i = 0; i < vobjp->getNumTEs(); ++i) { material_ids.push_back(vobjp->getRenderMaterialID(i)); + + // Make a copy to ensure we won't affect live material + // with any potential changes nor live changes will be + // reflected in a saved copy. + // Like changes from local material (reuses pointer) or + // from live editor (revert mechanics might modify this) + LLGLTFMaterial* old_mat = node->getObject()->getTE(i)->getGLTFRenderMaterial(); + if (old_mat) + { + LLPointer<LLGLTFMaterial> mat = new LLGLTFMaterial(*old_mat); + materials.push_back(mat); + } + else + { + materials.push_back(nullptr); + } } - node->savedGLTFMaterials(material_ids); + node->saveGLTFMaterialIds(material_ids); + + // processObjectProperties does not include overrides so this + // might need to be moved to LLGLTFMaterialOverrideDispatchHandler + node->saveGLTFRenderMaterials(materials); } } @@ -6606,7 +6648,8 @@ LLSelectNode::LLSelectNode(const LLSelectNode& nodep) } saveTextures(nodep.mSavedTextures); - savedGLTFMaterials(nodep.mSavedGLTFMaterials); + saveGLTFMaterialIds(nodep.mSavedGLTFMaterialIds); + saveGLTFRenderMaterials(nodep.mSavedGLTFRenderMaterials); } LLSelectNode::~LLSelectNode() @@ -6740,20 +6783,43 @@ void LLSelectNode::saveTextures(const uuid_vec_t& textures) } } -void LLSelectNode::savedGLTFMaterials(const uuid_vec_t& materials) +void LLSelectNode::saveGLTFMaterialIds(const uuid_vec_t& materials) { if (mObject.notNull()) { - mSavedGLTFMaterials.clear(); + mSavedGLTFMaterialIds.clear(); for (uuid_vec_t::const_iterator materials_it = materials.begin(); materials_it != materials.end(); ++materials_it) { - mSavedGLTFMaterials.push_back(*materials_it); + mSavedGLTFMaterialIds.push_back(*materials_it); } } } +void LLSelectNode::saveGLTFRenderMaterials(const gltf_materials_vec_t& materials) +{ + if (mObject.notNull()) + { + mSavedGLTFRenderMaterials.clear(); + + for (gltf_materials_vec_t::const_iterator mat_it = materials.begin(); + mat_it != materials.end(); ++mat_it) + { + mSavedGLTFRenderMaterials.push_back(*mat_it); + } + } +} + +LLGLTFMaterial* LLSelectNode::getSavedGLTFRenderMaterial(S32 te) +{ + if (mSavedGLTFRenderMaterials.size() > te) + { + return mSavedGLTFRenderMaterials[te].get(); + } + return nullptr; +} + void LLSelectNode::saveTextureScaleRatios(LLRender::eTexIndex index_to_query) { mTextureScaleRatios.clear(); diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h index 573eea7a8a..7e7c450767 100644 --- a/indra/newview/llselectmgr.h +++ b/indra/newview/llselectmgr.h @@ -161,6 +161,8 @@ typedef enum e_selection_type SELECT_TYPE_HUD }ESelectType; +typedef std::vector<LLPointer<LLGLTFMaterial> > gltf_materials_vec_t; + const S32 TE_SELECT_MASK_ALL = 0xFFFFFFFF; // Contains information about a selected object, particularly which TEs are selected. @@ -184,12 +186,21 @@ public: LLViewerObject* getObject(); void setObject(LLViewerObject* object); // *NOTE: invalidate stored textures and colors when # faces change + // Used by tools floater's color/texture pickers to restore changes 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); + // GLTF materials are applied to objects by ids, + // overrides get applied on top of materials resulting in + // final gltf material that users see. + // Ids get applied and restored by tools floater, + // overrides get applied in live material editor + void saveGLTFMaterialIds(const uuid_vec_t& materials); + void saveGLTFRenderMaterials(const gltf_materials_vec_t& materials); + LLGLTFMaterial* getSavedGLTFRenderMaterial(S32 te); + BOOL allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const; public: @@ -225,7 +236,8 @@ public: std::vector<LLColor4> mSavedColors; std::vector<LLColor4> mSavedShinyColors; uuid_vec_t mSavedTextures; - uuid_vec_t mSavedGLTFMaterials; + uuid_vec_t mSavedGLTFMaterialIds; + gltf_materials_vec_t mSavedGLTFRenderMaterials; std::vector<LLVector3> mTextureScaleRatios; std::vector<LLVector3> mSilhouetteVertices; // array of vertices to render silhouette of object std::vector<LLVector3> mSilhouetteNormals; // array of normals to render silhouette of object |