diff options
Diffstat (limited to 'indra/newview/llselectmgr.cpp')
-rw-r--r-- | indra/newview/llselectmgr.cpp | 385 |
1 files changed, 331 insertions, 54 deletions
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index cab0b74cd0..4b27e55309 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -63,6 +63,7 @@ #include "llfloatertools.h" #include "llframetimer.h" #include "llfocusmgr.h" +#include "llgltfmateriallist.h" #include "llhudeffecttrail.h" #include "llhudmanager.h" #include "llinventorymodel.h" @@ -1038,10 +1039,6 @@ void LLSelectMgr::addAsIndividual(LLViewerObject *objectp, S32 face, BOOL undoab // check to see if object is already in list LLSelectNode *nodep = mSelectedObjects->findNode(objectp); - // Reset (in anticipation of being set to an appropriate value by panel refresh, if they're up) - // - setTextureChannel(LLRender::DIFFUSE_MAP); - // if not in list, add it if (!nodep) { @@ -1168,8 +1165,8 @@ void LLSelectMgr::highlightObjectOnly(LLViewerObject* objectp) return; } - if ((gSavedSettings.getBOOL("SelectOwnedOnly") && !objectp->permYouOwner()) - || (gSavedSettings.getBOOL("SelectMovableOnly") && (!objectp->permMove() || objectp->isPermanentEnforced()))) + if ((gSavedSettings.getBOOL("SelectOwnedOnly") && !objectp->permYouOwner()) + || (gSavedSettings.getBOOL("SelectMovableOnly") && (!objectp->permMove() || objectp->isPermanentEnforced()))) { // only select my own objects return; @@ -1746,6 +1743,7 @@ void LLObjectSelection::applyNoCopyTextureToTEs(LLViewerInventoryItem* item) S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces()); bool texture_copied = false; + bool updated = false; for (S32 te = 0; te < num_tes; ++te) { if (node->isTESelected(te)) @@ -1754,27 +1752,85 @@ void LLObjectSelection::applyNoCopyTextureToTEs(LLViewerInventoryItem* item) // without making any copies if (!texture_copied) { - LLToolDragAndDrop::handleDropTextureProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); + LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); texture_copied = true; } // apply texture for the selected faces add(LLStatViewer::EDIT_TEXTURE, 1); object->setTEImage(te, image); - dialog_refresh_all(); - - // send the update to the simulator - object->sendTEUpdate(); + updated = true; } } + + if (updated) // not nessesary? sendTEUpdate update supposed to be done by sendfunc + { + dialog_refresh_all(); + + // send the update to the simulator + object->sendTEUpdate(); + } } } +bool LLObjectSelection::applyRestrictedPbrMaterialToTEs(LLViewerInventoryItem* item) +{ + if (!item) + { + return false; + } + + LLUUID asset_id = item->getAssetUUID(); + + bool material_copied_all_faces = true; + + for (iterator iter = begin(); iter != end(); ++iter) + { + LLSelectNode* node = *iter; + LLViewerObject* object = (*iter)->getObject(); + if (!object) + { + continue; + } + + S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces()); + bool material_copied = false; + for (S32 te = 0; te < num_tes; ++te) + { + if (node->isTESelected(te)) + { + //(no-copy), (no-modify), and (no-transfer) materials must be moved to the object's inventory only once + // without making any copies + if (!material_copied && asset_id.notNull()) + { + material_copied = (bool)LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); + } + if (!material_copied) + { + // Applying the material is not possible for this object given the current inventory + material_copied_all_faces = false; + break; + } + + // apply texture for the selected faces + // blank out most override data on the server + //add(LLStatViewer::EDIT_TEXTURE, 1); + object->setRenderMaterialID(te, asset_id); + } + } + } + + LLGLTFMaterialList::flushUpdates(); + + return material_copied_all_faces; +} + + //----------------------------------------------------------------------------- // selectionSetImage() //----------------------------------------------------------------------------- // *TODO: re-arch texture applying out of lltooldraganddrop -void LLSelectMgr::selectionSetImage(const LLUUID& imageid) +bool LLSelectMgr::selectionSetImage(const LLUUID& imageid) { // First for (no copy) textures and multiple object selection LLViewerInventoryItem* item = gInventory.getItem(imageid); @@ -1782,9 +1838,11 @@ void LLSelectMgr::selectionSetImage(const LLUUID& imageid) && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()) && (mSelectedObjects->getNumNodes() > 1) ) { - LL_WARNS() << "Attempted to apply no-copy texture to multiple objects" - << LL_ENDL; - return; + LL_DEBUGS() << "Attempted to apply no-copy texture " << imageid + << " to multiple objects" << LL_ENDL; + + LLNotificationsUtil::add("FailedToApplyTextureNoCopyToMultiple"); + return false; } struct f : public LLSelectedTEFunctor @@ -1794,27 +1852,31 @@ void LLSelectMgr::selectionSetImage(const LLUUID& imageid) f(LLViewerInventoryItem* item, const LLUUID& id) : mItem(item), mImageID(id) {} bool apply(LLViewerObject* objectp, S32 te) { - if(objectp && !objectp->permModify()) + if(!objectp || !objectp->permModify()) { return false; } + + // Might be better to run willObjectAcceptInventory + if (mItem && objectp->isAttachment()) + { + const LLPermissions& perm = mItem->getPermissions(); + BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE; + if (!unrestricted) + { + // Attachments are in world and in inventory simultaneously, + // at the moment server doesn't support such a situation. + return false; + } + } + if (mItem) { - if (te == -1) // all faces - { - LLToolDragAndDrop::dropTextureAllFaces(objectp, - mItem, - LLToolDragAndDrop::SOURCE_AGENT, - LLUUID::null); - } - else // one face - { - LLToolDragAndDrop::dropTextureOneFace(objectp, - te, - mItem, - LLToolDragAndDrop::SOURCE_AGENT, - LLUUID::null); - } + LLToolDragAndDrop::dropTextureOneFace(objectp, + te, + mItem, + LLToolDragAndDrop::SOURCE_AGENT, + LLUUID::null); } else // not an inventory item { @@ -1859,6 +1921,117 @@ void LLSelectMgr::selectionSetImage(const LLUUID& imageid) } } sendfunc(item); getSelection()->applyToObjects(&sendfunc); + + return true; +} + +//----------------------------------------------------------------------------- +// selectionSetGLTFMaterial() +//----------------------------------------------------------------------------- +bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id) +{ + // First for (no copy) textures and multiple object selection + LLViewerInventoryItem* item = gInventory.getItem(mat_id); + if (item + && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()) + && (mSelectedObjects->getNumNodes() > 1)) + { + LL_DEBUGS() << "Attempted to apply no-copy material " << mat_id + << "to multiple objects" << LL_ENDL; + + LLNotificationsUtil::add("FailedToApplyGLTFNoCopyToMultiple"); + return false; + } + + struct f : public LLSelectedTEFunctor + { + LLViewerInventoryItem* mItem; + LLUUID mMatId; + bool material_copied_any_face = false; + bool material_copied_all_faces = true; + f(LLViewerInventoryItem* item, const LLUUID& id) : mItem(item), mMatId(id) {} + bool apply(LLViewerObject* objectp, S32 te) + { + if (!objectp || !objectp->permModify()) + { + return false; + } + if (mItem && objectp->isAttachment()) + { + const LLPermissions& perm = mItem->getPermissions(); + BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE; + if (!unrestricted) + { + // Attachments are in world and in inventory simultaneously, + // at the moment server doesn't support such a situation. + return false; + } + } + LLUUID asset_id = mMatId; + if (mItem) + { + // If success, the material may be copied into the object's inventory + BOOL success = LLToolDragAndDrop::handleDropMaterialProtections(objectp, mItem, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); + if (!success) + { + return false; + } + asset_id = mItem->getAssetUUID(); + } + + // Blank out most override data on the object and send to server + objectp->setRenderMaterialID(te, asset_id); + + return true; + } + }; + + bool success = true; + if (item && + (!item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()) || + !item->getPermissions().allowOperationBy(PERM_TRANSFER, gAgent.getID()) || + !item->getPermissions().allowOperationBy(PERM_MODIFY, gAgent.getID()) + )) + { + success = success && getSelection()->applyRestrictedPbrMaterialToTEs(item); + } + else + { + f setfunc(item, mat_id); + success = success && getSelection()->applyToTEs(&setfunc); + } + + struct g : public LLSelectedObjectFunctor + { + LLViewerInventoryItem* mItem; + g(LLViewerInventoryItem* item) : mItem(item) {} + virtual bool apply(LLViewerObject* object) + { + if (object && !object->permModify()) + { + return false; + } + + if (!mItem) + { + // 1 particle effect per object + LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE); + effectp->setSourceObject(gAgentAvatarp); + effectp->setTargetObject(object); + effectp->setDuration(LL_HUD_DUR_SHORT); + effectp->setColor(LLColor4U(gAgent.getEffectColor())); + } + + dialog_refresh_all(); + object->sendTEUpdate(); + return true; + } + } sendfunc(item); + success = success && getSelection()->applyToObjects(&sendfunc); + + LLGLTFMaterialList::flushUpdates(); + + return success; } //----------------------------------------------------------------------------- @@ -2038,6 +2211,48 @@ BOOL LLSelectMgr::selectionRevertTextures() return revert_successful; } +void LLSelectMgr::selectionRevertGLTFMaterials() +{ + struct f : public LLSelectedTEFunctor + { + LLObjectSelectionHandle mSelectedObjects; + f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {} + bool apply(LLViewerObject* objectp, S32 te) + { + if (objectp && !objectp->permModify()) + { + return false; + } + + LLSelectNode* nodep = mSelectedObjects->findNode(objectp); + if (nodep && te < (S32)nodep->mSavedGLTFMaterialIds.size()) + { + // Restore base material + LLUUID asset_id = nodep->mSavedGLTFMaterialIds[te]; + + // Update material locally + objectp->setRenderMaterialID(te, asset_id, false /*wait for LLGLTFMaterialList update*/); + objectp->setTEGLTFMaterialOverride(te, nodep->mSavedGLTFOverrideMaterials[te]); + + // Enqueue update to server + if (asset_id.notNull()) + { + // Restore overrides and base material + LLGLTFMaterialList::queueApply(objectp, te, asset_id, nodep->mSavedGLTFOverrideMaterials[te]); + } + else + { + //blank override out + LLGLTFMaterialList::queueApply(objectp, te, asset_id); + } + + } + return true; + } + } setfunc(mSelectedObjects); + getSelection()->applyToTEs(&setfunc); +} + void LLSelectMgr::selectionSetBumpmap(U8 bumpmap, const LLUUID &image_id) { struct f : public LLSelectedTEFunctor @@ -2066,8 +2281,20 @@ void LLSelectMgr::selectionSetBumpmap(U8 bumpmap, const LLUUID &image_id) if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())) { LLViewerObject *object = mSelectedObjects->getFirstRootObject(); - if (!object) return; - LLToolDragAndDrop::handleDropTextureProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); + if (!object) + { + return; + } + const LLPermissions& perm = item->getPermissions(); + BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE; + BOOL attached = object->isAttachment(); + if (attached && !unrestricted) + { + // Attachments are in world and in inventory simultaneously, + // at the moment server doesn't support such a situation. + return; + } + LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); } getSelection()->applyToTEs(&setfunc); @@ -2126,8 +2353,20 @@ void LLSelectMgr::selectionSetShiny(U8 shiny, const LLUUID &image_id) if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())) { LLViewerObject *object = mSelectedObjects->getFirstRootObject(); - if (!object) return; - LLToolDragAndDrop::handleDropTextureProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); + if (!object) + { + return; + } + const LLPermissions& perm = item->getPermissions(); + BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE; + BOOL attached = object->isAttachment(); + if (attached && !unrestricted) + { + // Attachments are in world and in inventory simultaneously, + // at the moment server doesn't support such a situation. + return; + } + LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null); } getSelection()->applyToTEs(&setfunc); @@ -5625,9 +5864,38 @@ void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data if (can_copy && can_transfer) { - // 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; + gltf_materials_vec_t override_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_override = node->getObject()->getTE(i)->getGLTFMaterialOverride(); + if (old_override) + { + LLPointer<LLGLTFMaterial> mat = new LLGLTFMaterial(*old_override); + override_materials.push_back(mat); + } + else + { + override_materials.push_back(nullptr); + } + } + // processObjectProperties does not include overrides so this + // might need to be moved to LLGLTFMaterialOverrideDispatchHandler + node->saveGLTFMaterials(material_ids, override_materials); + } } node->mValid = TRUE; @@ -6093,9 +6361,6 @@ void LLSelectMgr::renderSilhouettes(BOOL for_hud) auto renderMeshSelection_f = [fogCfx, wireframe_selection](LLSelectNode* node, LLViewerObject* objectp, LLColor4 hlColor) { - //Need to because crash on ATI 3800 (and similar cards) MAINT-5018 - LLGLDisable multisample(LLPipeline::RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; if (shader) @@ -6383,6 +6648,7 @@ LLSelectNode::LLSelectNode(const LLSelectNode& nodep) } saveTextures(nodep.mSavedTextures); + saveGLTFMaterials(nodep.mSavedGLTFMaterialIds, nodep.mSavedGLTFOverrideMaterials); } LLSelectNode::~LLSelectNode() @@ -6516,6 +6782,27 @@ void LLSelectNode::saveTextures(const uuid_vec_t& textures) } } +void LLSelectNode::saveGLTFMaterials(const uuid_vec_t& materials, const gltf_materials_vec_t& override_materials) +{ + if (mObject.notNull()) + { + mSavedGLTFMaterialIds.clear(); + mSavedGLTFOverrideMaterials.clear(); + + for (uuid_vec_t::const_iterator materials_it = materials.begin(); + materials_it != materials.end(); ++materials_it) + { + mSavedGLTFMaterialIds.push_back(*materials_it); + } + + for (gltf_materials_vec_t::const_iterator mat_it = override_materials.begin(); + mat_it != override_materials.end(); ++mat_it) + { + mSavedGLTFOverrideMaterials.push_back(*mat_it); + } + } +} + void LLSelectNode::saveTextureScaleRatios(LLRender::eTexIndex index_to_query) { mTextureScaleRatios.clear(); @@ -6735,19 +7022,8 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color) { gGL.flush(); gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE); -#if GL_VERSION_1_1 - LLGLEnable fog(GL_FOG); - glFogi(GL_FOG_MODE, GL_LINEAR); -#endif - float d = (LLViewerCamera::getInstance()->getPointOfInterest()-LLViewerCamera::getInstance()->getOrigin()).magVec(); - LLColor4 fogCol = color * (F32)llclamp((LLSelectMgr::getInstance()->getSelectionCenterGlobal()-gAgentCamera.getCameraPositionGlobal()).magVec()/(LLSelectMgr::getInstance()->getBBoxOfSelection().getExtentLocal().magVec()*4), 0.0, 1.0); -#if GL_VERSION_1_1 - glFogf(GL_FOG_START, d); - glFogf(GL_FOG_END, d*(1 + (LLViewerCamera::getInstance()->getView() / LLViewerCamera::getInstance()->getDefaultFOV()))); - glFogfv(GL_FOG_COLOR, fogCol.mV); -#endif - - LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL); + + LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL); gGL.flush(); gGL.begin(LLRender::LINES); { @@ -7621,7 +7897,7 @@ S32 LLObjectSelection::getSelectedObjectRenderCost() for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter) { // add the cost of each individual texture in the linkset - cost += iter->second; + cost += LLVOVolume::getTextureCost(*iter); } textures.clear(); @@ -7643,7 +7919,7 @@ S32 LLObjectSelection::getSelectedObjectRenderCost() for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter) { // add the cost of each individual texture in the linkset - cost += iter->second; + cost += LLVOVolume::getTextureCost(*iter); } textures.clear(); @@ -8315,6 +8591,7 @@ DEF_DUMMY_CHECK_FUNCTOR(int) DEF_DUMMY_CHECK_FUNCTOR(LLColor4) DEF_DUMMY_CHECK_FUNCTOR(LLMediaEntry) DEF_DUMMY_CHECK_FUNCTOR(LLPointer<LLMaterial>) +DEF_DUMMY_CHECK_FUNCTOR(LLPointer<LLGLTFMaterial>) DEF_DUMMY_CHECK_FUNCTOR(std::string) DEF_DUMMY_CHECK_FUNCTOR(std::vector<std::string>) |