diff options
Diffstat (limited to 'indra/newview/lllocalgltfmaterials.cpp')
-rw-r--r-- | indra/newview/lllocalgltfmaterials.cpp | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/indra/newview/lllocalgltfmaterials.cpp b/indra/newview/lllocalgltfmaterials.cpp index a9099b1ce9..d464ea0571 100644 --- a/indra/newview/lllocalgltfmaterials.cpp +++ b/indra/newview/lllocalgltfmaterials.cpp @@ -45,6 +45,7 @@ #include "llmaterialmgr.h" #include "llnotificationsutil.h" #include "llscrolllistctrl.h" +#include "lltextureentry.h" #include "lltinygltfhelper.h" #include "llviewertexture.h" @@ -118,6 +119,15 @@ S32 LLLocalGLTFMaterial::getIndexInFile() const return mMaterialIndex; } +void LLLocalGLTFMaterial::addTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.insert(te); +} +void LLLocalGLTFMaterial::removeTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.erase(te); +} + /* update functions */ bool LLLocalGLTFMaterial::updateSelf() { @@ -154,6 +164,27 @@ bool LLLocalGLTFMaterial::updateSelf() gGLTFMaterialList.addMaterial(mWorldID, this); mUpdateRetries = LL_LOCAL_UPDATE_RETRIES; + + for (LLTextureEntry* entry : mTextureEntires) + { + // Normally a change in applied material id is supposed to + // drop overrides thus reset material, but local materials + // currently reuse their existing asset id, and purpose is + // to preview how material will work in-world, overrides + // included, so do an override to render update instead. + LLGLTFMaterial* override_mat = entry->getGLTFMaterialOverride(); + if (override_mat) + { + // do not create a new material, reuse existing pointer + LLFetchedGLTFMaterial* render_mat = (LLFetchedGLTFMaterial*)entry->getGLTFRenderMaterial(); + if (render_mat) + { + *render_mat = *this; + render_mat->applyOverride(*override_mat); + } + } + } + updated = true; } @@ -214,12 +245,18 @@ bool LLLocalGLTFMaterial::loadMaterial() LLStringUtil::toLower(filename_lc); std::string material_name; - // Might be a good idea to make these textures into local textures - decode_successful = LLTinyGLTFHelper::getMaterialFromFile( - mFilename, - mMaterialIndex, - this, - material_name); + tinygltf::Model model; + decode_successful = LLTinyGLTFHelper::loadModel(mFilename, model); + if (decode_successful) + { + // Might be a good idea to make these textures into local textures + decode_successful = LLTinyGLTFHelper::getMaterialFromModel( + mFilename, + model, + mMaterialIndex, + this, + material_name); + } if (!material_name.empty()) { @@ -308,7 +345,10 @@ S32 LLLocalGLTFMaterialMgr::addUnit(const std::vector<std::string>& filenames) S32 LLLocalGLTFMaterialMgr::addUnit(const std::string& filename) { - S32 materials_in_file = LLTinyGLTFHelper::getMaterialCountFromFile(filename); + tinygltf::Model model; + LLTinyGLTFHelper::loadModel(filename, model); + + S32 materials_in_file = model.materials.size(); if (materials_in_file <= 0) { return 0; |