From 9346b45188462056698083f4f83fe8fecbe19bdf Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 29 Sep 2022 22:38:40 +0300 Subject: SL-17653 Multi-material file support for local materials --- indra/newview/llmaterialeditor.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 27694e9ce4..7270317b8c 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -1176,6 +1176,8 @@ void LLMaterialFilePicker::notify(const std::vector& filenames) if (filenames.size() > 0) { + // Todo: there is no point creating LLMaterialEditor before + // loading material, just creates unnessesary work if decode fails LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); if (me) { @@ -1235,7 +1237,7 @@ void LLMaterialFilePicker::textureLoadedCallback(BOOL success, LLViewerFetchedTe { } -void LLMaterialEditor::loadMaterialFromFile(const std::string& filename) +void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 index) { tinygltf::TinyGLTF loader; std::string error_msg; @@ -1264,19 +1266,26 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename) return; } - if (model_in.materials.empty()) + if (model_in.materials.empty() || (index >= model_in.materials.size())) { // materials are missing LLNotificationsUtil::add("CannotUploadMaterial"); return; } - if (model_in.materials.size() == 1) + if (index >= 0) { + // Prespecified material + loadMaterial(model_in, filename_lc, index); + } + else if (model_in.materials.size() == 1) + { + // Only one, just load it loadMaterial(model_in, filename_lc, 0); } else { + // Promt user to select material std::list material_list; std::vector::const_iterator mat_iter = model_in.materials.begin(); std::vector::const_iterator mat_end = model_in.materials.end(); -- cgit v1.2.3 From 332ddc67de2de245a52d9db3be20f4ba8051f166 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 29 Sep 2022 23:17:49 +0300 Subject: SL-17653 Small change in material loading order --- indra/newview/llmaterialeditor.cpp | 80 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 47 deletions(-) (limited to 'indra/newview/llmaterialeditor.cpp') diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 7270317b8c..a72d38223f 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -1152,40 +1152,6 @@ void LLMaterialEditor::onCancelMsgCallback(const LLSD& notification, const LLSD& } } -class LLMaterialFilePicker : public LLFilePickerThread -{ -public: - LLMaterialFilePicker(); - virtual void notify(const std::vector& filenames); - static void textureLoadedCallback(BOOL success, LLViewerFetchedTexture* src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata); - -}; - -LLMaterialFilePicker::LLMaterialFilePicker() - : LLFilePickerThread(LLFilePicker::FFLOAD_MATERIAL) -{ -} - -void LLMaterialFilePicker::notify(const std::vector& filenames) -{ - if (LLAppViewer::instance()->quitRequested()) - { - return; - } - - - if (filenames.size() > 0) - { - // Todo: there is no point creating LLMaterialEditor before - // loading material, just creates unnessesary work if decode fails - LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); - if (me) - { - me->loadMaterialFromFile(filenames[0]); - } - } -} - static void pack_textures( LLPointer& base_color_img, LLPointer& normal_img, @@ -1233,10 +1199,6 @@ static void pack_textures( } } -void LLMaterialFilePicker::textureLoadedCallback(BOOL success, LLViewerFetchedTexture* src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata) -{ -} - void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 index) { tinygltf::TinyGLTF loader; @@ -1266,22 +1228,31 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind return; } - if (model_in.materials.empty() || (index >= model_in.materials.size())) + if (model_in.materials.empty()) { // materials are missing LLNotificationsUtil::add("CannotUploadMaterial"); return; } + if (index >= 0 && model_in.materials.size() <= index) + { + // material is missing + LLNotificationsUtil::add("CannotUploadMaterial"); + return; + } + + LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); + if (index >= 0) { // Prespecified material - loadMaterial(model_in, filename_lc, index); + me->loadMaterial(model_in, filename_lc, index); } else if (model_in.materials.size() == 1) { // Only one, just load it - loadMaterial(model_in, filename_lc, 0); + me->loadMaterial(model_in, filename_lc, 0); } else { @@ -1302,12 +1273,12 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind } } LLFloaterComboOptions::showUI( - [this, model_in, filename_lc](const std::string& option, S32 index) + [me, model_in, filename_lc](const std::string& option, S32 index) { - loadMaterial(model_in, filename_lc, index); + me->loadMaterial(model_in, filename_lc, index); }, - getString("material_selection_title"), - getString("material_selection_text"), + me->getString("material_selection_title"), + me->getString("material_selection_text"), material_list ); } @@ -1315,7 +1286,7 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::string &filename_lc, S32 index) { - if (model_in.materials.size() < index) + if (model_in.materials.size() <= index) { return; } @@ -1410,7 +1381,9 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std:: setFromGltfMetaData(filename_lc, model_in, index); setHasUnsavedChanges(true); + openFloater(); + setFocus(TRUE); applyToSelection(); } @@ -1704,7 +1677,20 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti void LLMaterialEditor::importMaterial() { - (new LLMaterialFilePicker())->getFile(); + LLFilePickerReplyThread::startPicker( + [](const std::vector& filenames, LLFilePicker::ELoadFilter load_filter, LLFilePicker::ESaveFilter save_filter) + { + if (LLAppViewer::instance()->quitRequested()) + { + return; + } + if (filenames.size() > 0) + { + LLMaterialEditor::loadMaterialFromFile(filenames[0], -1); + } + }, + LLFilePicker::FFLOAD_MATERIAL, + true); } class LLRemderMaterialFunctor : public LLSelectedTEFunctor -- cgit v1.2.3