diff options
Diffstat (limited to 'indra/newview/llmaterialeditor.cpp')
-rw-r--r-- | indra/newview/llmaterialeditor.cpp | 295 |
1 files changed, 218 insertions, 77 deletions
diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 5ae16db1f6..7cd9b9198f 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -67,6 +67,24 @@ const std::string MATERIAL_EMISSIVE_DEFAULT_NAME = "Emissive"; const LLUUID LIVE_MATERIAL_EDITOR_KEY("6cf97162-8b68-49eb-b627-79886c9fd17d"); +// Dirty flags +static const U32 MATERIAL_BASE_COLOR_DIRTY = 0x1 << 0; +static const U32 MATERIAL_BASE_TRANSPARENCY_DIRTY = 0x1 << 1; +static const U32 MATERIAL_BASE_COLOR_TEX_DIRTY = 0x1 << 2; + +static const U32 MATERIAL_NORMAL_TEX_DIRTY = 0x1 << 3; + +static const U32 MATERIAL_METALLIC_ROUGHTNESS_TEX_DIRTY = 0x1 << 4; +static const U32 MATERIAL_METALLIC_ROUGHTNESS_METALNESS_DIRTY = 0x1 << 5; +static const U32 MATERIAL_METALLIC_ROUGHTNESS_ROUGHNESS_DIRTY = 0x1 << 6; + +static const U32 MATERIAL_EMISIVE_COLOR_DIRTY = 0x1 << 7; +static const U32 MATERIAL_EMISIVE_TEX_DIRTY = 0x1 << 8; + +static const U32 MATERIAL_DOUBLE_SIDED_DIRTY = 0x1 << 9; +static const U32 MATERIAL_ALPHA_MODE_DIRTY = 0x1 << 10; +static const U32 MATERIAL_ALPHA_CUTOFF_DIRTY = 0x1 << 11; + LLFloaterComboOptions::LLFloaterComboOptions() : LLFloater(LLSD()) { @@ -199,7 +217,7 @@ private: // Default constructor LLMaterialEditor::LLMaterialEditor(const LLSD& key) : LLPreview(key) - , mHasUnsavedChanges(false) + , mUnsavedChanges(0) , mExpectedUploadCost(0) , mUploadingTexturesCount(0) { @@ -251,33 +269,30 @@ BOOL LLMaterialEditor::postBuild() getChild<LLUICtrl>("emissive_upload_fee")->setTextArg("[FEE]", llformat("%d", upload_cost)); getChild<LLUICtrl>("normal_upload_fee")->setTextArg("[FEE]", llformat("%d", upload_cost)); - boost::function<void(LLUICtrl*, void*)> changes_callback = [this](LLUICtrl * ctrl, void*) + boost::function<void(LLUICtrl*, void*)> changes_callback = [this](LLUICtrl * ctrl, void* userData) { - setHasUnsavedChanges(true); + const U32 *flag = (const U32*)userData; + markChangesUnsaved(*flag); // Apply changes to object live applyToSelection(); }; - childSetCommitCallback("double sided", changes_callback, NULL); + childSetCommitCallback("double sided", changes_callback, (void*)&MATERIAL_DOUBLE_SIDED_DIRTY); // BaseColor - childSetCommitCallback("base color", changes_callback, NULL); - childSetCommitCallback("transparency", changes_callback, NULL); - childSetCommitCallback("alpha mode", changes_callback, NULL); - childSetCommitCallback("alpha cutoff", changes_callback, NULL); - - // Metallic-Roughness - childSetCommitCallback("metalness factor", changes_callback, NULL); - childSetCommitCallback("roughness factor", changes_callback, NULL); + childSetCommitCallback("base color", changes_callback, (void*)&MATERIAL_BASE_COLOR_DIRTY); + childSetCommitCallback("transparency", changes_callback, (void*)&MATERIAL_BASE_TRANSPARENCY_DIRTY); + childSetCommitCallback("alpha mode", changes_callback, (void*)&MATERIAL_ALPHA_MODE_DIRTY); + childSetCommitCallback("alpha cutoff", changes_callback, (void*)&MATERIAL_ALPHA_CUTOFF_DIRTY); // Metallic-Roughness - childSetCommitCallback("metalness factor", changes_callback, NULL); - childSetCommitCallback("roughness factor", changes_callback, NULL); + childSetCommitCallback("metalness factor", changes_callback, (void*)&MATERIAL_METALLIC_ROUGHTNESS_METALNESS_DIRTY); + childSetCommitCallback("roughness factor", changes_callback, (void*)&MATERIAL_METALLIC_ROUGHTNESS_ROUGHNESS_DIRTY); // Emissive - childSetCommitCallback("emissive color", changes_callback, NULL); + childSetCommitCallback("emissive color", changes_callback, (void*)&MATERIAL_EMISIVE_COLOR_DIRTY); - childSetVisible("unsaved_changes", mHasUnsavedChanges); + childSetVisible("unsaved_changes", mUnsavedChanges); getChild<LLUICtrl>("total_upload_fee")->setTextArg("[FEE]", llformat("%d", 0)); @@ -302,6 +317,11 @@ void LLMaterialEditor::onClickCloseBtn(bool app_quitting) void LLMaterialEditor::onClose(bool app_quitting) { + if (mSelectionUpdateSlot.connected()) + { + mSelectionUpdateSlot.disconnect(); + } + LLPreview::onClose(app_quitting); } @@ -314,6 +334,7 @@ void LLMaterialEditor::setBaseColorId(const LLUUID& id) { mBaseColorTextureCtrl->setValue(id); mBaseColorTextureCtrl->setDefaultImageAssetID(id); + mBaseColorTextureCtrl->setTentative(FALSE); } void LLMaterialEditor::setBaseColorUploadId(const LLUUID& id) @@ -328,7 +349,7 @@ void LLMaterialEditor::setBaseColorUploadId(const LLUUID& id) // Only set if we will need to upload this texture mBaseColorTextureUploadId = id; } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_BASE_COLOR_TEX_DIRTY); } LLColor4 LLMaterialEditor::getBaseColor() @@ -389,6 +410,7 @@ void LLMaterialEditor::setMetallicRoughnessId(const LLUUID& id) { mMetallicTextureCtrl->setValue(id); mMetallicTextureCtrl->setDefaultImageAssetID(id); + mMetallicTextureCtrl->setTentative(FALSE); } void LLMaterialEditor::setMetallicRoughnessUploadId(const LLUUID& id) @@ -400,7 +422,7 @@ void LLMaterialEditor::setMetallicRoughnessUploadId(const LLUUID& id) childSetValue("metallic_upload_fee", getString("upload_fee_string")); mMetallicTextureUploadId = id; } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_METALLIC_ROUGHTNESS_TEX_DIRTY); } F32 LLMaterialEditor::getMetalnessFactor() @@ -432,6 +454,7 @@ void LLMaterialEditor::setEmissiveId(const LLUUID& id) { mEmissiveTextureCtrl->setValue(id); mEmissiveTextureCtrl->setDefaultImageAssetID(id); + mEmissiveTextureCtrl->setTentative(FALSE); } void LLMaterialEditor::setEmissiveUploadId(const LLUUID& id) @@ -443,7 +466,7 @@ void LLMaterialEditor::setEmissiveUploadId(const LLUUID& id) childSetValue("emissive_upload_fee", getString("upload_fee_string")); mEmissiveTextureUploadId = id; } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_EMISIVE_TEX_DIRTY); } LLColor4 LLMaterialEditor::getEmissiveColor() @@ -465,6 +488,7 @@ void LLMaterialEditor::setNormalId(const LLUUID& id) { mNormalTextureCtrl->setValue(id); mNormalTextureCtrl->setDefaultImageAssetID(id); + mNormalTextureCtrl->setTentative(FALSE); } void LLMaterialEditor::setNormalUploadId(const LLUUID& id) @@ -476,7 +500,7 @@ void LLMaterialEditor::setNormalUploadId(const LLUUID& id) childSetValue("normal_upload_fee", getString("upload_fee_string")); mNormalTextureUploadId = id; } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_NORMAL_TEX_DIRTY); } bool LLMaterialEditor::getDoubleSided() @@ -489,12 +513,22 @@ void LLMaterialEditor::setDoubleSided(bool double_sided) childSetValue("double sided", double_sided); } -void LLMaterialEditor::setHasUnsavedChanges(bool value) +void LLMaterialEditor::resetUnsavedChanges() { - mHasUnsavedChanges = value; - childSetVisible("unsaved_changes", value); + mUnsavedChanges = 0; + childSetVisible("unsaved_changes", false); + setCanSave(false); + + mExpectedUploadCost = 0; + getChild<LLUICtrl>("total_upload_fee")->setTextArg("[FEE]", llformat("%d", mExpectedUploadCost)); +} - if (mHasUnsavedChanges) +void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag) +{ + mUnsavedChanges |= dirty_flag; + childSetVisible("unsaved_changes", mUnsavedChanges); + + if (mUnsavedChanges) { const LLInventoryItem* item = getItem(); if (item) @@ -589,7 +623,7 @@ void LLMaterialEditor::onCommitBaseColorTexture(LLUICtrl * ctrl, const LLSD & da // the texture that is not in use childSetValue("base_color_upload_fee", getString("no_upload_fee_string")); } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_BASE_COLOR_TEX_DIRTY); applyToSelection(); } @@ -604,7 +638,7 @@ void LLMaterialEditor::onCommitMetallicTexture(LLUICtrl * ctrl, const LLSD & dat { childSetValue("metallic_upload_fee", getString("no_upload_fee_string")); } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_METALLIC_ROUGHTNESS_TEX_DIRTY); applyToSelection(); } @@ -619,7 +653,7 @@ void LLMaterialEditor::onCommitEmissiveTexture(LLUICtrl * ctrl, const LLSD & dat { childSetValue("emissive_upload_fee", getString("no_upload_fee_string")); } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_EMISIVE_TEX_DIRTY); applyToSelection(); } @@ -634,7 +668,7 @@ void LLMaterialEditor::onCommitNormalTexture(LLUICtrl * ctrl, const LLSD & data) { childSetValue("normal_upload_fee", getString("no_upload_fee_string")); } - setHasUnsavedChanges(true); + markChangesUnsaved(MATERIAL_NORMAL_TEX_DIRTY); applyToSelection(); } @@ -1218,7 +1252,7 @@ void LLMaterialEditor::onSaveAsMsgCallback(const LLSD& notification, const LLSD& else { std::string buffer = getEncodedAsset(); - LLPointer<LLInventoryCallback> cb = new LLMaterialEditorCopiedCallback(buffer, getKey(), mHasUnsavedChanges); + LLPointer<LLInventoryCallback> cb = new LLMaterialEditorCopiedCallback(buffer, getKey(), mUnsavedChanges); copy_inventory_item( gAgent.getID(), item->getPermissions().getOwner(), @@ -1246,7 +1280,7 @@ void LLMaterialEditor::onSaveAsMsgCallback(const LLSD& notification, const LLSD& void LLMaterialEditor::onClickCancel() { - if (mHasUnsavedChanges) + if (mUnsavedChanges) { LLNotificationsUtil::add("UsavedMaterialChanges", LLSD(), LLSD(), boost::bind(&LLMaterialEditor::onCancelMsgCallback, this, _1, _2)); } @@ -1463,42 +1497,61 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind ); } } +void LLMaterialEditor::onSelectionChanged() +{ + mUnsavedChanges = 0; + 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); @@ -1527,7 +1580,6 @@ void LLMaterialEditor::loadFromGLTFMaterial(LLUUID &asset_id) LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); me->mMaterialName = LLTrans::getString("New Material"); me->setTitle(me->mMaterialName); - me->setHasUnsavedChanges(true); me->setFromGLTFMaterial(gGLTFMaterialList.getMaterial(asset_id)); me->openFloater(); me->setFocus(TRUE); @@ -1629,7 +1681,7 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std:: setFromGltfMetaData(filename_lc, model_in, index); - setHasUnsavedChanges(true); + markChangesUnsaved(U32_MAX); openFloater(); setFocus(TRUE); @@ -1967,8 +2019,8 @@ private: class LLRenderMaterialOverrideFunctor : public LLSelectedTEFunctor { public: - LLRenderMaterialOverrideFunctor(LLMaterialEditor * me, std::string const & url, LLUUID const & asset_id) - : mEditor(me), mCapUrl(url), mAssetID(asset_id) + LLRenderMaterialOverrideFunctor(LLMaterialEditor * me, std::string const & url) + : mEditor(me), mCapUrl(url) { } @@ -1983,12 +2035,78 @@ public: if (objectp && objectp->permModify() && objectp->getVolume()) { - LLPointer<LLGLTFMaterial> material = new LLGLTFMaterial(); - - mEditor->getGLTFMaterial(material); + // Get material from object + // Selection can cover multiple objects, and live editor is + // supposed to overwrite changed values only + LLTextureEntry* tep = objectp->getTE(te); + LLPointer<LLGLTFMaterial> material = tep->getGLTFRenderMaterial(); + + if (material.isNull()) + { + material = new LLGLTFMaterial(); + } + else + { + material = new LLGLTFMaterial(*material); + } + + // Override object's values with values from editor where appropriate + if (mEditor->getUnsavedChangesFlags() & MATERIAL_BASE_COLOR_DIRTY) + { + material->mBaseColor = mEditor->getBaseColor(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_BASE_TRANSPARENCY_DIRTY) + { + material->mBaseColor.mV[3] = mEditor->getTransparency(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_BASE_COLOR_TEX_DIRTY) + { + material->mBaseColorId = mEditor->getBaseColorId(); + } + + if (mEditor->getUnsavedChangesFlags() & MATERIAL_NORMAL_TEX_DIRTY) + { + material->mNormalId = mEditor->getNormalId(); + } + + if (mEditor->getUnsavedChangesFlags() & MATERIAL_METALLIC_ROUGHTNESS_TEX_DIRTY) + { + material->mMetallicRoughnessId = mEditor->getMetallicRoughnessId(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_METALLIC_ROUGHTNESS_METALNESS_DIRTY) + { + material->mMetallicFactor = mEditor->getMetalnessFactor(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_METALLIC_ROUGHTNESS_ROUGHNESS_DIRTY) + { + material->mRoughnessFactor = mEditor->getRoughnessFactor(); + } + + if (mEditor->getUnsavedChangesFlags() & MATERIAL_EMISIVE_COLOR_DIRTY) + { + material->mEmissiveColor = mEditor->getEmissiveColor(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_EMISIVE_TEX_DIRTY) + { + material->mEmissiveId = mEditor->getEmissiveId(); + } + + if (mEditor->getUnsavedChangesFlags() & MATERIAL_DOUBLE_SIDED_DIRTY) + { + material->mDoubleSided = mEditor->getDoubleSided(); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_ALPHA_MODE_DIRTY) + { + material->setAlphaMode(mEditor->getAlphaMode()); + } + if (mEditor->getUnsavedChangesFlags() & MATERIAL_ALPHA_CUTOFF_DIRTY) + { + material->mAlphaCutoff = mEditor->getAlphaCutoff(); + } std::string overrides_json = material->asJSON(); + LLSD overrides = llsd::map( "object_id", objectp->getID(), "side", te, @@ -2002,7 +2120,6 @@ public: private: LLMaterialEditor * mEditor; std::string mCapUrl; - LLUUID mAssetID; }; void LLMaterialEditor::applyToSelection() @@ -2021,7 +2138,7 @@ void LLMaterialEditor::applyToSelection() { LLObjectSelectionHandle selected_objects = LLSelectMgr::getInstance()->getSelection(); // TODO figure out how to get the right asset id in cases where we don't have a good one - LLRenderMaterialOverrideFunctor override_func(this, url, mAssetID); + LLRenderMaterialOverrideFunctor override_func(this, url); selected_objects->applyToTEs(&override_func); } else @@ -2081,21 +2198,40 @@ bool LLMaterialEditor::setFromSelection() { struct LLSelectedTEGetGLTFRenderMaterial : public LLSelectedTEGetFunctor<LLPointer<LLGLTFMaterial> > { - LLPointer<LLGLTFMaterial> get(LLViewerObject* object, S32 te_index) + LLPointer<LLGLTFMaterial> get(LLViewerObject* objectp, S32 te_index) { - return object->getTE(te_index)->getGLTFRenderMaterial(); // present user with combined override + asset + if (!objectp) + { + return nullptr; + } + LLTextureEntry *tep = objectp->getTE(te_index); + if (!tep) + { + return nullptr; + } + return tep->getGLTFRenderMaterial(); // present user with combined override + asset } } func; LLPointer<LLGLTFMaterial> mat; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat); + bool identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, mat); if (mat.notNull()) { setFromGLTFMaterial(mat); - return true; + } + else + { + // pick defaults from a blank material; + LLGLTFMaterial blank_mat; + setFromGLTFMaterial(&blank_mat); } - return false; + mBaseColorTextureCtrl->setTentative(!identical); + mMetallicTextureCtrl->setTentative(!identical); + mEmissiveTextureCtrl->setTentative(!identical); + mNormalTextureCtrl->setTentative(!identical); + + return mat.notNull(); } @@ -2134,7 +2270,7 @@ void LLMaterialEditor::loadAsset() { mAssetStatus = PREVIEW_ASSET_LOADED; loadDefaults(); - setHasUnsavedChanges(false); + resetUnsavedChanges(); setEnableEditing(allow_modify && !source_library); } else @@ -2159,7 +2295,7 @@ void LLMaterialEditor::loadAsset() LL_WARNS() << "Can't find object " << mObjectUUID << " associated with notecard." << LL_ENDL; mAssetID.setNull(); mAssetStatus = PREVIEW_ASSET_LOADED; - setHasUnsavedChanges(false); + resetUnsavedChanges(); setEnableEditing(allow_modify && !source_library); return; } @@ -2246,7 +2382,7 @@ void LLMaterialEditor::onLoadComplete(const LLUUID& asset_uuid, BOOL allow_modify = editor->canModify(editor->mObjectUUID, editor->getItem()); BOOL source_library = editor->mObjectUUID.isNull() && gInventory.isObjectDescendentOf(editor->mItemUUID, gInventory.getLibraryRootFolderID()); editor->setEnableEditing(allow_modify && !source_library); - editor->setHasUnsavedChanges(false); + editor->resetUnsavedChanges(); editor->mAssetStatus = PREVIEW_ASSET_LOADED; editor->setEnabled(true); // ready for use } @@ -2424,6 +2560,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 +2584,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() |