Skip to content
Snippets Groups Projects
Commit 332ddc67 authored by Andrey Kleshchev's avatar Andrey Kleshchev
Browse files

SL-17653 Small change in material loading order

parent 9346b451
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
...@@ -267,7 +267,7 @@ bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat, S32 index) ...@@ -267,7 +267,7 @@ bool LLLocalGLTFMaterial::loadMaterial(LLPointer<LLGLTFMaterial> mat, S32 index)
if (!material_in.name.empty()) if (!material_in.name.empty())
{ {
mShortName = material_in.name; mShortName = gDirUtilp->getBaseFileName(filename_lc, true) + " (" + material_in.name + ")";
} }
// get base color texture // get base color texture
......
...@@ -1152,40 +1152,6 @@ void LLMaterialEditor::onCancelMsgCallback(const LLSD& notification, const LLSD& ...@@ -1152,40 +1152,6 @@ void LLMaterialEditor::onCancelMsgCallback(const LLSD& notification, const LLSD&
} }
} }
class LLMaterialFilePicker : public LLFilePickerThread
{
public:
LLMaterialFilePicker();
virtual void notify(const std::vector<std::string>& 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<std::string>& 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( static void pack_textures(
LLPointer<LLImageRaw>& base_color_img, LLPointer<LLImageRaw>& base_color_img,
LLPointer<LLImageRaw>& normal_img, LLPointer<LLImageRaw>& normal_img,
...@@ -1233,10 +1199,6 @@ static void pack_textures( ...@@ -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) void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 index)
{ {
tinygltf::TinyGLTF loader; tinygltf::TinyGLTF loader;
...@@ -1266,22 +1228,31 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind ...@@ -1266,22 +1228,31 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
return; return;
} }
if (model_in.materials.empty() || (index >= model_in.materials.size())) if (model_in.materials.empty())
{ {
// materials are missing // materials are missing
LLNotificationsUtil::add("CannotUploadMaterial"); LLNotificationsUtil::add("CannotUploadMaterial");
return; 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) if (index >= 0)
{ {
// Prespecified material // Prespecified material
loadMaterial(model_in, filename_lc, index); me->loadMaterial(model_in, filename_lc, index);
} }
else if (model_in.materials.size() == 1) else if (model_in.materials.size() == 1)
{ {
// Only one, just load it // Only one, just load it
loadMaterial(model_in, filename_lc, 0); me->loadMaterial(model_in, filename_lc, 0);
} }
else else
{ {
...@@ -1302,12 +1273,12 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind ...@@ -1302,12 +1273,12 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
} }
} }
LLFloaterComboOptions::showUI( 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"), me->getString("material_selection_title"),
getString("material_selection_text"), me->getString("material_selection_text"),
material_list material_list
); );
} }
...@@ -1315,7 +1286,7 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind ...@@ -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) 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; return;
} }
...@@ -1410,7 +1381,9 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std:: ...@@ -1410,7 +1381,9 @@ void LLMaterialEditor::loadMaterial(const tinygltf::Model &model_in, const std::
setFromGltfMetaData(filename_lc, model_in, index); setFromGltfMetaData(filename_lc, model_in, index);
setHasUnsavedChanges(true); setHasUnsavedChanges(true);
openFloater(); openFloater();
setFocus(TRUE);
applyToSelection(); applyToSelection();
} }
...@@ -1704,7 +1677,20 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti ...@@ -1704,7 +1677,20 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti
void LLMaterialEditor::importMaterial() void LLMaterialEditor::importMaterial()
{ {
(new LLMaterialFilePicker())->getFile(); LLFilePickerReplyThread::startPicker(
[](const std::vector<std::string>& 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 class LLRemderMaterialFunctor : public LLSelectedTEFunctor
......
...@@ -103,7 +103,7 @@ class LLMaterialEditor : public LLPreview, public LLVOInventoryListener ...@@ -103,7 +103,7 @@ class LLMaterialEditor : public LLPreview, public LLVOInventoryListener
void loadAsset() override; void loadAsset() override;
// @index if -1 and file contains more than one material, // @index if -1 and file contains more than one material,
// will promt to select specific one // will promt to select specific one
void loadMaterialFromFile(const std::string& filename, S32 index = -1); static void loadMaterialFromFile(const std::string& filename, S32 index = -1);
static void onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status); static void onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status);
......
...@@ -970,12 +970,7 @@ void LLFloaterTexturePicker::onBtnUpload(void* userdata) ...@@ -970,12 +970,7 @@ void LLFloaterTexturePicker::onBtnUpload(void* userdata)
LLLocalGLTFMaterialMgr::getInstance()->getFilenameAndIndex(tracking_id, filename, index); LLLocalGLTFMaterialMgr::getInstance()->getFilenameAndIndex(tracking_id, filename, index);
if (!filename.empty()) if (!filename.empty())
{ {
LLMaterialEditor* me = (LLMaterialEditor*)LLFloaterReg::getInstance("material_editor"); LLMaterialEditor::loadMaterialFromFile(filename, index);
if (me)
{
me->loadMaterialFromFile(filename, index);
me->setFocus(TRUE);
}
} }
} }
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment