diff options
Diffstat (limited to 'indra/newview/lltexturectrl.cpp')
-rw-r--r-- | indra/newview/lltexturectrl.cpp | 598 |
1 files changed, 436 insertions, 162 deletions
diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp index 0ce82a1297..7e399a6808 100644 --- a/indra/newview/lltexturectrl.cpp +++ b/indra/newview/lltexturectrl.cpp @@ -41,12 +41,15 @@ #include "llfolderviewmodel.h" #include "llinventory.h" #include "llinventoryfunctions.h" +#include "llinventoryicon.h" #include "llinventorymodelbackgroundfetch.h" #include "llinventoryobserver.h" #include "llinventorypanel.h" #include "lllineeditor.h" +#include "llmaterialeditor.h" #include "llui.h" #include "llviewerinventory.h" +#include "llviewermenufile.h" // LLFilePickerReplyThread #include "llpermissions.h" #include "llpreviewtexture.h" #include "llsaleinfo.h" @@ -70,19 +73,12 @@ #include "llradiogroup.h" #include "llfloaterreg.h" #include "lllocalbitmaps.h" +#include "lllocalgltfmaterials.h" #include "llerror.h" #include "llavatarappearancedefines.h" -static const S32 LOCAL_TRACKING_ID_COLUMN = 1; - -//static const char CURRENT_IMAGE_NAME[] = "Current Texture"; -//static const char WHITE_IMAGE_NAME[] = "Blank Texture"; -//static const char NO_IMAGE_NAME[] = "None"; - - - //static bool get_is_predefined_texture(LLUUID asset_id) { @@ -152,7 +148,6 @@ LLFloaterTexturePicker::LLFloaterTexturePicker( const std::string& label, PermissionMask immediate_filter_perm_mask, PermissionMask dnd_filter_perm_mask, - PermissionMask non_immediate_filter_perm_mask, BOOL can_apply_immediately, LLUIImagePtr fallback_image) : LLFloater(LLSD()), @@ -171,7 +166,6 @@ LLFloaterTexturePicker::LLFloaterTexturePicker( mFilterEdit(NULL), mImmediateFilterPermMask(immediate_filter_perm_mask), mDnDFilterPermMask(dnd_filter_perm_mask), - mNonImmediateFilterPermMask(non_immediate_filter_perm_mask), mContextConeOpacity(0.f), mSelectedItemPinned( FALSE ), mCanApply(true), @@ -181,10 +175,11 @@ LLFloaterTexturePicker::LLFloaterTexturePicker( mOnFloaterCloseCallback(NULL), mSetImageAssetIDCallback(NULL), mOnUpdateImageStatsCallback(NULL), - mBakeTextureEnabled(FALSE) + mBakeTextureEnabled(FALSE), + mInventoryPickType(LLTextureCtrl::PICK_TEXTURE) { - buildFromFile("floater_texture_ctrl.xml"); mCanApplyImmediately = can_apply_immediately; + buildFromFile("floater_texture_ctrl.xml"); setCanMinimize(FALSE); } @@ -237,12 +232,20 @@ void LLFloaterTexturePicker::setImageID(const LLUUID& image_id, bool set_selecti mInventoryPanel->setSelection(item_id, TAKE_FOCUS_NO); } } - - - } } +void LLFloaterTexturePicker::setImageIDFromItem(const LLInventoryItem* itemp, bool set_selection) +{ + LLUUID asset_id = itemp->getAssetUUID(); + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL && asset_id.isNull()) + { + // If an inventory item has a null asset, consider it a valid blank material(gltf) + asset_id = LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID; + } + setImageID(asset_id, set_selection); +} + void LLFloaterTexturePicker::setActive( BOOL active ) { if (!active && getChild<LLUICtrl>("Pipette")->getValue().asBoolean()) @@ -255,11 +258,10 @@ void LLFloaterTexturePicker::setActive( BOOL active ) void LLFloaterTexturePicker::setCanApplyImmediately(BOOL b) { mCanApplyImmediately = b; - if (!mCanApplyImmediately) - { - getChild<LLUICtrl>("apply_immediate_check")->setValue(FALSE); - } - updateFilterPermMask(); + + LLUICtrl *apply_checkbox = getChild<LLUICtrl>("apply_immediate_check"); + apply_checkbox->setValue(mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview")); + apply_checkbox->setEnabled(mCanApplyImmediately); } void LLFloaterTexturePicker::stopUsingPipette() @@ -272,7 +274,59 @@ void LLFloaterTexturePicker::stopUsingPipette() void LLFloaterTexturePicker::updateImageStats() { - if (mTexturep.notNull()) + if (mGLTFMaterial.notNull()) + { + S32 width = 0; + S32 height = 0; + + bool has_texture = false; + + if (mGLTFMaterial->mBaseColorTexture) + { + width = llmax(width, mGLTFMaterial->mBaseColorTexture->getFullWidth()); + height = llmax(height, mGLTFMaterial->mBaseColorTexture->getFullHeight()); + has_texture = true; + } + if (mGLTFMaterial->mNormalTexture) + { + width = llmax(width, mGLTFMaterial->mNormalTexture->getFullWidth()); + height = llmax(height, mGLTFMaterial->mNormalTexture->getFullHeight()); + has_texture = true; + } + if (mGLTFMaterial->mMetallicRoughnessTexture) + { + width = llmax(width, mGLTFMaterial->mMetallicRoughnessTexture->getFullWidth()); + height = llmax(height, mGLTFMaterial->mMetallicRoughnessTexture->getFullHeight()); + has_texture = true; + } + if (mGLTFMaterial->mEmissiveTexture) + { + width = llmax(width, mGLTFMaterial->mEmissiveTexture->getFullWidth()); + height = llmax(height, mGLTFMaterial->mEmissiveTexture->getFullHeight()); + has_texture = true; + } + + if (width > 0 && height > 0) + { + std::string formatted_dims = llformat("%d x %d", width, height); + mResolutionLabel->setTextArg("[DIMENSIONS]", formatted_dims); + if (mOnUpdateImageStatsCallback) + { + mOnUpdateImageStatsCallback(mTexturep); + } + } + else if (has_texture) + { + // unknown resolution + mResolutionLabel->setTextArg("[DIMENSIONS]", std::string("[? x ?]")); + } + else + { + // No textures - no applicable resolution (may be show some max value instead?) + mResolutionLabel->setTextArg("[DIMENSIONS]", std::string("")); + } + } + else if (mTexturep.notNull()) { //RN: have we received header data for this image? if (mTexturep->getFullWidth() > 0 && mTexturep->getFullHeight() > 0) @@ -306,8 +360,24 @@ BOOL LLFloaterTexturePicker::handleDragAndDrop( BOOL handled = FALSE; bool is_mesh = cargo_type == DAD_MESH; + bool is_texture = cargo_type == DAD_TEXTURE; + bool is_material = cargo_type == DAD_MATERIAL; + + bool allow_dnd = false; + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + allow_dnd = is_material; + } + else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + allow_dnd = is_texture || is_mesh; + } + else + { + allow_dnd = is_texture || is_mesh || is_material; + } - if ((cargo_type == DAD_TEXTURE) || is_mesh) + if (allow_dnd) { LLInventoryItem *item = (LLInventoryItem *)cargo_data; @@ -321,13 +391,12 @@ BOOL LLFloaterTexturePicker::handleDragAndDrop( if (mod) item_perm_mask |= PERM_MODIFY; if (xfer) item_perm_mask |= PERM_TRANSFER; - //PermissionMask filter_perm_mask = getFilterPermMask(); Commented out due to no-copy texture loss. PermissionMask filter_perm_mask = mDnDFilterPermMask; if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask ) { if (drop) { - setImageID( item->getAssetUUID() ); + setImageIDFromItem(item); commitIfImmediateSet(); } @@ -416,12 +485,8 @@ BOOL LLFloaterTexturePicker::postBuild() childSetAction("None", LLFloaterTexturePicker::onBtnNone,this); childSetAction("Blank", LLFloaterTexturePicker::onBtnBlank,this); - - childSetCommitCallback("show_folders_check", onShowFolders, this); - getChildView("show_folders_check")->setVisible( FALSE); - - mFilterEdit = getChild<LLFilterEditor>("inventory search editor"); - mFilterEdit->setCommitCallback(boost::bind(&LLFloaterTexturePicker::onFilterEdit, this, _2)); + mFilterEdit = getChild<LLFilterEditor>("inventory search editor"); + mFilterEdit->setCommitCallback(boost::bind(&LLFloaterTexturePicker::onFilterEdit, this, _2)); mInventoryPanel = getChild<LLInventoryPanel>("inventory panel"); @@ -431,12 +496,12 @@ BOOL LLFloaterTexturePicker::postBuild() if(mInventoryPanel) { - U32 filter_types = 0x0; - filter_types |= 0x1 << LLInventoryType::IT_TEXTURE; - filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT; + // to avoid having to make an assumption about which option is + // selected at startup, we call the same function that is triggered + // when a texture/materials/both choice is made and let it take care + // of setting the filters + refreshInventoryFilter(); - mInventoryPanel->setFilterTypes(filter_types); - //mInventoryPanel->setFilterPermMask(getFilterPermMask()); //Commented out due to no-copy texture loss. mInventoryPanel->setFilterPermMask(mImmediateFilterPermMask); mInventoryPanel->setSelectCallback(boost::bind(&LLFloaterTexturePicker::onSelectionChange, this, _1, _2)); mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS); @@ -469,30 +534,23 @@ BOOL LLFloaterTexturePicker::postBuild() mLocalScrollCtrl = getChild<LLScrollListCtrl>("l_name_list"); mLocalScrollCtrl->setCommitCallback(onLocalScrollCommit, this); - LLLocalBitmapMgr::getInstance()->feedScrollList(mLocalScrollCtrl); + refreshLocalList(); mNoCopyTextureSelected = FALSE; - getChild<LLUICtrl>("apply_immediate_check")->setValue(gSavedSettings.getBOOL("TextureLivePreview")); + getChild<LLUICtrl>("apply_immediate_check")->setValue(mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview")); childSetCommitCallback("apply_immediate_check", onApplyImmediateCheck, this); - - if (!mCanApplyImmediately) - { - getChildView("show_folders_check")->setEnabled(FALSE); - } + getChildView("apply_immediate_check")->setEnabled(mCanApplyImmediately); getChild<LLUICtrl>("Pipette")->setCommitCallback( boost::bind(&LLFloaterTexturePicker::onBtnPipette, this)); childSetAction("Cancel", LLFloaterTexturePicker::onBtnCancel,this); childSetAction("Select", LLFloaterTexturePicker::onBtnSelect,this); - // update permission filter once UI is fully initialized - updateFilterPermMask(); mSavedFolderState.setApply(FALSE); LLToolPipette::getInstance()->setToolSelectCallback(boost::bind(&LLFloaterTexturePicker::onTextureSelect, this, _1)); getChild<LLComboBox>("l_bake_use_texture_combo_box")->setCommitCallback(onBakeTextureSelect, this); - getChild<LLCheckBoxCtrl>("hide_base_mesh_region")->setCommitCallback(onHideBaseMeshRegionCheck, this); setBakeTextureEnabled(TRUE); return TRUE; @@ -504,10 +562,11 @@ void LLFloaterTexturePicker::draw() static LLCachedControl<F32> max_opacity(gSavedSettings, "PickerContextOpacity", 0.4f); drawConeToOwner(mContextConeOpacity, max_opacity, mOwner); + // This is going to spam mOnUpdateImageStatsCallback, + // either move elsewhere or fix to cause update once per image updateImageStats(); // if we're inactive, gray out "apply immediate" checkbox - getChildView("show_folders_check")->setEnabled(mActive && mCanApplyImmediately && !mNoCopyTextureSelected); getChildView("Select")->setEnabled(mActive && mCanApply); getChildView("Pipette")->setEnabled(mActive); getChild<LLUICtrl>("Pipette")->setValue(LLToolMgr::getInstance()->getCurrentTool() == LLToolPipette::getInstance()); @@ -516,28 +575,39 @@ void LLFloaterTexturePicker::draw() if( mOwner ) { mTexturep = NULL; - if(mImageAssetID.notNull()) - { - LLPointer<LLViewerFetchedTexture> texture = NULL; + mGLTFMaterial = NULL; + if (mImageAssetID.notNull()) + { + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + mGLTFMaterial = (LLFetchedGLTFMaterial*) gGLTFMaterialList.getMaterial(mImageAssetID); + llassert(mGLTFMaterial == nullptr || dynamic_cast<LLFetchedGLTFMaterial*>(gGLTFMaterialList.getMaterial(mImageAssetID)) != nullptr); + } + else + { + LLPointer<LLViewerFetchedTexture> texture = NULL; - if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID)) - { - LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject(); - if (obj) - { - LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID); - texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL; - } - } + if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID)) + { + // TODO: Fix this! Picker is not warrantied to be connected to a selection + // LLSelectMgr shouldn't be used in texture picker + LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject(); + if (obj) + { + LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID); + texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL; + } + } - if (texture.isNull()) - { - texture = LLViewerTextureManager::getFetchedTexture(mImageAssetID); - } + if (texture.isNull()) + { + texture = LLViewerTextureManager::getFetchedTexture(mImageAssetID); + } - mTexturep = texture; - mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW); - } + mTexturep = texture; + mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW); + } + } if (mTentativeLabel) { @@ -545,7 +615,7 @@ void LLFloaterTexturePicker::draw() } getChildView("Default")->setEnabled(mImageAssetID != mDefaultImageAssetID || mTentative); - getChildView("Blank")->setEnabled(mImageAssetID != mBlankImageAssetID || mTentative); + getChildView("Blank")->setEnabled((mImageAssetID != mBlankImageAssetID && mBlankImageAssetID.notNull()) || mTentative); getChildView("None")->setEnabled(mAllowNoTexture && (!mImageAssetID.isNull() || mTentative)); LLFloater::draw(); @@ -623,6 +693,11 @@ void LLFloaterTexturePicker::draw() const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL copyable_only, BOOL ignore_library) { + if (asset_id.isNull()) + { + return LLUUID::null; + } + LLViewerInventoryCategory::cat_array_t cats; LLViewerInventoryItem::item_array_t items; LLAssetIDMatches asset_id_matches(asset_id); @@ -664,12 +739,6 @@ const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL co return LLUUID::null; } -PermissionMask LLFloaterTexturePicker::getFilterPermMask() -{ - bool apply_immediate = getChild<LLUICtrl>("apply_immediate_check")->getValue().asBoolean(); - return apply_immediate ? mImmediateFilterPermMask : mNonImmediateFilterPermMask; -} - void LLFloaterTexturePicker::commitIfImmediateSet() { if (!mNoCopyTextureSelected && mOnFloaterCommitCallback && mCanApply) @@ -712,8 +781,9 @@ void LLFloaterTexturePicker::onBtnBlank(void* userdata) void LLFloaterTexturePicker::onBtnNone(void* userdata) { LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata; + self->setCanApply(true, true); self->setImageID( LLUUID::null ); - self->commitCancel(); + self->commitIfImmediateSet(); } /* @@ -750,8 +820,18 @@ void LLFloaterTexturePicker::onBtnSelect(void* userdata) { if (self->mLocalScrollCtrl->getVisible() && !self->mLocalScrollCtrl->getAllSelected().empty()) { - LLUUID temp_id = self->mLocalScrollCtrl->getFirstSelected()->getColumn(LOCAL_TRACKING_ID_COLUMN)->getValue().asUUID(); - local_id = LLLocalBitmapMgr::getInstance()->getWorldID(temp_id); + LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue(); + LLUUID temp_id = data["id"]; + S32 asset_type = data["type"].asInteger(); + + if (LLAssetType::AT_MATERIAL == asset_type) + { + local_id = LLLocalGLTFMaterialMgr::getInstance()->getWorldID(temp_id); + } + else + { + local_id = LLLocalBitmapMgr::getInstance()->getWorldID(temp_id); + } } } @@ -793,12 +873,12 @@ void LLFloaterTexturePicker::onSelectionChange(const std::deque<LLFolderViewItem { mNoCopyTextureSelected = TRUE; } - setImageID(itemp->getAssetUUID(),false); + setImageIDFromItem(itemp, false); mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here? if(!mPreviewSettingChanged) { - mCanPreview = gSavedSettings.getBOOL("TextureLivePreview"); + mCanPreview = mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview"); } else { @@ -823,20 +903,19 @@ void LLFloaterTexturePicker::onModeSelect(LLUICtrl* ctrl, void *userdata) self->getChild<LLButton>("Default")->setVisible(index == 0 ? TRUE : FALSE); self->getChild<LLButton>("Blank")->setVisible(index == 0 ? TRUE : FALSE); self->getChild<LLButton>("None")->setVisible(index == 0 ? TRUE : FALSE); - self->getChild<LLButton>("Pipette")->setVisible(index == 0 ? TRUE : FALSE); self->getChild<LLFilterEditor>("inventory search editor")->setVisible(index == 0 ? TRUE : FALSE); self->getChild<LLInventoryPanel>("inventory panel")->setVisible(index == 0 ? TRUE : FALSE); - /*self->getChild<LLCheckBox>("show_folders_check")->setVisible(mode); - no idea under which conditions the above is even shown, needs testing. */ - self->getChild<LLButton>("l_add_btn")->setVisible(index == 1 ? TRUE : FALSE); self->getChild<LLButton>("l_rem_btn")->setVisible(index == 1 ? TRUE : FALSE); self->getChild<LLButton>("l_upl_btn")->setVisible(index == 1 ? TRUE : FALSE); self->getChild<LLScrollListCtrl>("l_name_list")->setVisible(index == 1 ? TRUE : FALSE); self->getChild<LLComboBox>("l_bake_use_texture_combo_box")->setVisible(index == 2 ? TRUE : FALSE); - self->getChild<LLCheckBoxCtrl>("hide_base_mesh_region")->setVisible(FALSE);// index == 2 ? TRUE : FALSE); + + bool pipette_visible = (index == 0) + && (self->mInventoryPickType != LLTextureCtrl::PICK_MATERIAL); + self->getChild<LLButton>("Pipette")->setVisible(pipette_visible); if (index == 2) { @@ -898,11 +977,20 @@ void LLFloaterTexturePicker::onModeSelect(LLUICtrl* ctrl, void *userdata) // static void LLFloaterTexturePicker::onBtnAdd(void* userdata) { - if (LLLocalBitmapMgr::getInstance()->addUnit() == true) - { - LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata; - LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); - } + LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)userdata; + + if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL) + { + LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_MATERIAL_TEXTURE, true); + } + else if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_IMAGE, true); + } + else if (self->mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + LLFilePickerReplyThread::startPicker(boost::bind(&onPickerCallback, _1, self->getHandle()), LLFilePicker::FFLOAD_MATERIAL, true); + } } // static @@ -913,22 +1001,32 @@ void LLFloaterTexturePicker::onBtnRemove(void* userdata) if (!selected_items.empty()) { + for(std::vector<LLScrollListItem*>::iterator iter = selected_items.begin(); iter != selected_items.end(); iter++) { LLScrollListItem* list_item = *iter; if (list_item) { - LLUUID tracking_id = list_item->getColumn(LOCAL_TRACKING_ID_COLUMN)->getValue().asUUID(); - LLLocalBitmapMgr::getInstance()->delUnit(tracking_id); + LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue(); + LLUUID tracking_id = data["id"]; + S32 asset_type = data["type"].asInteger(); + + if (LLAssetType::AT_MATERIAL == asset_type) + { + LLLocalGLTFMaterialMgr::getInstance()->delUnit(tracking_id); + } + else + { + LLLocalBitmapMgr::getInstance()->delUnit(tracking_id); + } } } self->getChild<LLButton>("l_rem_btn")->setEnabled(false); self->getChild<LLButton>("l_upl_btn")->setEnabled(false); - LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); + self->refreshLocalList(); } - } // static @@ -944,15 +1042,29 @@ void LLFloaterTexturePicker::onBtnUpload(void* userdata) /* currently only allows uploading one by one, picks the first item from the selection list. (not the vector!) in the future, it might be a good idea to check the vector size and if more than one units is selected - opt for multi-image upload. */ - - LLUUID tracking_id = (LLUUID)self->mLocalScrollCtrl->getSelectedItemLabel(LOCAL_TRACKING_ID_COLUMN); - std::string filename = LLLocalBitmapMgr::getInstance()->getFilename(tracking_id); - if (!filename.empty()) - { - LLFloaterReg::showInstance("upload_image", LLSD(filename)); - } + LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue(); + LLUUID tracking_id = data["id"]; + S32 asset_type = data["type"].asInteger(); + if (LLAssetType::AT_MATERIAL == asset_type) + { + std::string filename; + S32 index; + LLLocalGLTFMaterialMgr::getInstance()->getFilenameAndIndex(tracking_id, filename, index); + if (!filename.empty()) + { + LLMaterialEditor::loadMaterialFromFile(filename, index); + } + } + else + { + std::string filename = LLLocalBitmapMgr::getInstance()->getFilename(tracking_id); + if (!filename.empty()) + { + LLFloaterReg::showInstance("upload_image", LLSD(filename)); + } + } } //static @@ -968,8 +1080,20 @@ void LLFloaterTexturePicker::onLocalScrollCommit(LLUICtrl* ctrl, void* userdata) if (has_selection) { - LLUUID tracking_id = (LLUUID)self->mLocalScrollCtrl->getSelectedItemLabel(LOCAL_TRACKING_ID_COLUMN); - LLUUID inworld_id = LLLocalBitmapMgr::getInstance()->getWorldID(tracking_id); + LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue(); + LLUUID tracking_id = data["id"]; + S32 asset_type = data["type"].asInteger(); + LLUUID inworld_id; + + if (LLAssetType::AT_MATERIAL == asset_type) + { + inworld_id = LLLocalGLTFMaterialMgr::getInstance()->getWorldID(tracking_id); + } + else + { + inworld_id = LLLocalBitmapMgr::getInstance()->getWorldID(tracking_id); + } + if (self->mSetImageAssetIDCallback) { self->mSetImageAssetIDCallback(inworld_id); @@ -986,22 +1110,6 @@ void LLFloaterTexturePicker::onLocalScrollCommit(LLUICtrl* ctrl, void* userdata) } // static -void LLFloaterTexturePicker::onShowFolders(LLUICtrl* ctrl, void *user_data) -{ - LLCheckBoxCtrl* check_box = (LLCheckBoxCtrl*)ctrl; - LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data; - - if (check_box->get()) - { - picker->mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS); - } - else - { - picker->mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NO_FOLDERS); - } -} - -// static void LLFloaterTexturePicker::onApplyImmediateCheck(LLUICtrl* ctrl, void *user_data) { LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data; @@ -1009,7 +1117,6 @@ void LLFloaterTexturePicker::onApplyImmediateCheck(LLUICtrl* ctrl, void *user_da LLCheckBoxCtrl* check_box = (LLCheckBoxCtrl*)ctrl; gSavedSettings.setBOOL("TextureLivePreview", check_box->get()); - picker->updateFilterPermMask(); picker->commitIfImmediateSet(); } @@ -1072,7 +1179,7 @@ void LLFloaterTexturePicker::onBakeTextureSelect(LLUICtrl* ctrl, void *user_data if (!self->mPreviewSettingChanged) { - self->mCanPreview = gSavedSettings.getBOOL("TextureLivePreview"); + self->mCanPreview = self->mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview"); } else { @@ -1086,18 +1193,6 @@ void LLFloaterTexturePicker::onBakeTextureSelect(LLUICtrl* ctrl, void *user_data } } -//static -void LLFloaterTexturePicker::onHideBaseMeshRegionCheck(LLUICtrl* ctrl, void *user_data) -{ - //LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data; - //LLCheckBoxCtrl* check_box = (LLCheckBoxCtrl*)ctrl; -} - -void LLFloaterTexturePicker::updateFilterPermMask() -{ - //mInventoryPanel->setFilterPermMask( getFilterPermMask() ); Commented out due to no-copy texture loss. -} - void LLFloaterTexturePicker::setCanApply(bool can_preview, bool can_apply) { getChildRef<LLUICtrl>("Select").setEnabled(can_apply); @@ -1105,7 +1200,7 @@ void LLFloaterTexturePicker::setCanApply(bool can_preview, bool can_apply) getChildRef<LLUICtrl>("apply_immediate_check").setVisible(can_preview); mCanApply = can_apply; - mCanPreview = can_preview ? gSavedSettings.getBOOL("TextureLivePreview") : false; + mCanPreview = can_preview ? (mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview")) : false; mPreviewSettingChanged = true; } @@ -1143,6 +1238,48 @@ void LLFloaterTexturePicker::onFilterEdit(const std::string& search_string ) mInventoryPanel->setFilterSubString(search_string); } +void LLFloaterTexturePicker::refreshLocalList() +{ + mLocalScrollCtrl->clearRows(); + + if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL) + { + LLLocalBitmapMgr::getInstance()->feedScrollList(mLocalScrollCtrl); + LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(mLocalScrollCtrl); + } + else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + LLLocalBitmapMgr::getInstance()->feedScrollList(mLocalScrollCtrl); + } + else if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(mLocalScrollCtrl); + } +} + +void LLFloaterTexturePicker::refreshInventoryFilter() +{ + U32 filter_types = 0x0; + + if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL) + { + filter_types |= 0x1 << LLInventoryType::IT_TEXTURE; + filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT; + filter_types |= 0x1 << LLInventoryType::IT_MATERIAL; + } + else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + filter_types |= 0x1 << LLInventoryType::IT_TEXTURE; + filter_types |= 0x1 << LLInventoryType::IT_SNAPSHOT; + } + else if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + filter_types |= 0x1 << LLInventoryType::IT_MATERIAL; + } + + mInventoryPanel->setFilterTypes(filter_types); +} + void LLFloaterTexturePicker::setLocalTextureEnabled(BOOL enabled) { mModeSelector->setEnabledByValue(1, enabled); @@ -1170,13 +1307,103 @@ void LLFloaterTexturePicker::setBakeTextureEnabled(BOOL enabled) onModeSelect(0, this); } +void LLFloaterTexturePicker::setInventoryPickType(LLTextureCtrl::EPickInventoryType type) +{ + mInventoryPickType = type; + refreshLocalList(); + refreshInventoryFilter(); + + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + getChild<LLButton>("Pipette")->setVisible(false); + } + else + { + S32 index = mModeSelector->getValue().asInteger(); + getChild<LLButton>("Pipette")->setVisible(index == 0); + } + + if (!mLabel.empty()) + { + std::string pick = getString("pick title"); + + setTitle(pick + mLabel); + } + else if(mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + setTitle(getString("pick_material")); + } + else + { + setTitle(getString("pick_texture")); + } +} + +void LLFloaterTexturePicker::setImmediateFilterPermMask(PermissionMask mask) +{ + mImmediateFilterPermMask = mask; + mInventoryPanel->setFilterPermMask(mask); +} + +void LLFloaterTexturePicker::onPickerCallback(const std::vector<std::string>& filenames, LLHandle<LLFloater> handle) +{ + std::vector<std::string>::const_iterator iter = filenames.begin(); + while (iter != filenames.end()) + { + if (!iter->empty()) + { + std::string temp_exten = gDirUtilp->getExtension(*iter); + if (temp_exten == "gltf" || temp_exten == "glb") + { + LLLocalGLTFMaterialMgr::getInstance()->addUnit(*iter); + } + else + { + LLLocalBitmapMgr::getInstance()->addUnit(*iter); + } + } + iter++; + } + + // Todo: this should referesh all pickers, not just a current one + if (!handle.isDead()) + { + LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)handle.get(); + self->mLocalScrollCtrl->clearRows(); + + if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE_MATERIAL) + { + LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); + LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); + } + else if (self->mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + LLLocalBitmapMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); + } + else if (self->mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + LLLocalGLTFMaterialMgr::getInstance()->feedScrollList(self->mLocalScrollCtrl); + } + } +} + void LLFloaterTexturePicker::onTextureSelect( const LLTextureEntry& te ) { LLUUID inventory_item_id = findItemID(te.getID(), TRUE); if (inventory_item_id.notNull()) { LLToolPipette::getInstance()->setResult(TRUE, ""); - setImageID(te.getID()); + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + // tes have no data about material ids + // Plus gltf materials are layered with overrides, + // which mean that end result might have no id. + LL_WARNS() << "tes have no data about material ids" << LL_ENDL; + } + else + { + setImageID(te.getID()); + } mNoCopyTextureSelected = FALSE; LLInventoryItem* itemp = gInventory.getItem(inventory_item_id); @@ -1208,15 +1435,16 @@ LLTextureCtrl::LLTextureCtrl(const LLTextureCtrl::Params& p) mOnCloseCallback(NULL), mOnSelectCallback(NULL), mBorderColor( p.border_color() ), - mAllowNoTexture( FALSE ), + mAllowNoTexture( p.allow_no_texture ), mAllowLocalTexture( TRUE ), mImmediateFilterPermMask( PERM_NONE ), - mNonImmediateFilterPermMask( PERM_NONE ), mCanApplyImmediately( FALSE ), mNeedsRawImageData( FALSE ), mValid( TRUE ), mShowLoadingPlaceholder( TRUE ), mOpenTexPreview(false), + mBakeTextureEnabled(true), + mInventoryPickType(PICK_TEXTURE), mImageAssetID(p.image_id), mDefaultImageAssetID(p.default_image_id), mDefaultImageName(p.default_image_name), @@ -1304,6 +1532,17 @@ void LLTextureCtrl::setCanApply(bool can_preview, bool can_apply) } } +void LLTextureCtrl::setImmediateFilterPermMask(PermissionMask mask) +{ + mImmediateFilterPermMask = mask; + + LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get(); + if (floaterp) + { + floaterp->setImmediateFilterPermMask(mask); + } +} + void LLTextureCtrl::setVisible( BOOL visible ) { if( !visible ) @@ -1389,7 +1628,6 @@ void LLTextureCtrl::showPicker(BOOL take_focus) mLabel, mImmediateFilterPermMask, mDnDFilterPermMask, - mNonImmediateFilterPermMask, mCanApplyImmediately, mFallbackImage); mFloaterHandle = floaterp->getHandle(); @@ -1406,14 +1644,10 @@ void LLTextureCtrl::showPicker(BOOL take_focus) if (texture_floaterp) { texture_floaterp->setOnFloaterCommitCallback(boost::bind(&LLTextureCtrl::onFloaterCommit, this, _1, _2)); - } - if (texture_floaterp) - { texture_floaterp->setSetImageAssetIDCallback(boost::bind(&LLTextureCtrl::setImageAssetID, this, _1)); - } - if (texture_floaterp) - { - texture_floaterp->setBakeTextureEnabled(TRUE); + + texture_floaterp->setBakeTextureEnabled(mBakeTextureEnabled); + texture_floaterp->setInventoryPickType(mInventoryPickType); } LLFloater* root_floater = gFloaterView->getParentFloater(this); @@ -1476,8 +1710,16 @@ BOOL LLTextureCtrl::handleMouseDown(S32 x, S32 y, MASK mask) if (!mOpenTexPreview) { showPicker(FALSE); - //grab textures first... - LLInventoryModelBackgroundFetch::instance().start(gInventory.findCategoryUUIDForType(LLFolderType::FT_TEXTURE)); + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + //grab materials first... + LLInventoryModelBackgroundFetch::instance().start(gInventory.findCategoryUUIDForType(LLFolderType::FT_MATERIAL)); + } + else + { + //grab textures first... + LLInventoryModelBackgroundFetch::instance().start(gInventory.findCategoryUUIDForType(LLFolderType::FT_TEXTURE)); + } //...then start full inventory fetch. LLInventoryModelBackgroundFetch::instance().start(); handled = TRUE; @@ -1521,9 +1763,9 @@ void LLTextureCtrl::onFloaterClose() void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLUUID id) { - LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get(); + LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get(); - if( floaterp && getEnabled()) + if( floaterp && getEnabled()) { if (op == TEXTURE_CANCEL) mViewModel->resetDirty(); @@ -1544,15 +1786,15 @@ void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLUUID id) } else { - mImageItemID = floaterp->findItemID(floaterp->getAssetID(), FALSE); - LL_DEBUGS() << "mImageItemID: " << mImageItemID << LL_ENDL; - mImageAssetID = floaterp->getAssetID(); - LL_DEBUGS() << "mImageAssetID: " << mImageAssetID << LL_ENDL; + mImageItemID = floaterp->findItemID(floaterp->getAssetID(), FALSE); + LL_DEBUGS() << "mImageItemID: " << mImageItemID << LL_ENDL; + mImageAssetID = floaterp->getAssetID(); + LL_DEBUGS() << "mImageAssetID: " << mImageAssetID << LL_ENDL; } if (op == TEXTURE_SELECT && mOnSelectCallback) { - mOnSelectCallback( this, LLSD() ); + mOnSelectCallback(this, LLSD()); } else if (op == TEXTURE_CANCEL && mOnCancelCallback) { @@ -1563,8 +1805,10 @@ void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLUUID id) // If the "no_commit_on_selection" parameter is set // we commit only when user presses OK in the picker // (i.e. op == TEXTURE_SELECT) or texture changes via DnD. - if (mCommitOnSelection || op == TEXTURE_SELECT) - onCommit(); + if (mCommitOnSelection || op == TEXTURE_SELECT) + { + onCommit(); + } } } } @@ -1609,8 +1853,9 @@ void LLTextureCtrl::setImageAssetID( const LLUUID& asset_id ) } } -void LLTextureCtrl::setBakeTextureEnabled(BOOL enabled) +void LLTextureCtrl::setBakeTextureEnabled(bool enabled) { + mBakeTextureEnabled = enabled; LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get(); if (floaterp) { @@ -1618,6 +1863,16 @@ void LLTextureCtrl::setBakeTextureEnabled(BOOL enabled) } } +void LLTextureCtrl::setInventoryPickType(EPickInventoryType type) +{ + mInventoryPickType = type; + LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get(); + if (floaterp) + { + floaterp->setInventoryPickType(type); + } +} + BOOL LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, @@ -1629,11 +1884,26 @@ BOOL LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask, // returns true, then the cast was valid, and we can perform // the third test without problems. LLInventoryItem* item = (LLInventoryItem*)cargo_data; - bool is_mesh = cargo_type == DAD_MESH; - if (getEnabled() && - ((cargo_type == DAD_TEXTURE) || is_mesh) && - allowDrop(item)) + bool is_mesh = cargo_type == DAD_MESH; + bool is_texture = cargo_type == DAD_TEXTURE; + bool is_material = cargo_type == DAD_MATERIAL; + + bool allow_dnd = false; + if (mInventoryPickType == LLTextureCtrl::PICK_MATERIAL) + { + allow_dnd = is_material; + } + else if (mInventoryPickType == LLTextureCtrl::PICK_TEXTURE) + { + allow_dnd = is_texture || is_mesh; + } + else + { + allow_dnd = is_texture || is_mesh || is_material; + } + + if (getEnabled() && allow_dnd && allowDrop(item, cargo_type, tooltip_msg)) { if (drop) { @@ -1697,7 +1967,7 @@ void LLTextureCtrl::draw() } else//mImageAssetID == LLUUID::null { - mTexturep = NULL; + mTexturep = NULL; } // Border @@ -1785,7 +2055,7 @@ void LLTextureCtrl::draw() LLUICtrl::draw(); } -BOOL LLTextureCtrl::allowDrop(LLInventoryItem* item) +BOOL LLTextureCtrl::allowDrop(LLInventoryItem* item, EDragAndDropType cargo_type, std::string& tooltip_msg) { BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID()); BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID()); @@ -1797,8 +2067,6 @@ BOOL LLTextureCtrl::allowDrop(LLInventoryItem* item) if (mod) item_perm_mask |= PERM_MODIFY; if (xfer) item_perm_mask |= PERM_TRANSFER; -// PermissionMask filter_perm_mask = mCanApplyImmediately ? commented out due to no-copy texture loss. -// mImmediateFilterPermMask : mNonImmediateFilterPermMask; PermissionMask filter_perm_mask = mImmediateFilterPermMask; if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask ) { @@ -1813,6 +2081,12 @@ BOOL LLTextureCtrl::allowDrop(LLInventoryItem* item) } else { + PermissionMask mask = PERM_COPY | PERM_TRANSFER; + if ((filter_perm_mask & mask) == mask + && cargo_type == DAD_TEXTURE) + { + tooltip_msg.assign(LLTrans::getString("TooltipTextureRestrictedDrop")); + } return FALSE; } } |