From 99179c232f2b63bdc6d7364f225b9c34a4f4d0b8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 29 Jun 2022 21:43:24 -0500 Subject: SL-17685 Add missing files --- indra/newview/llgltfmateriallist.cpp | 186 +++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 indra/newview/llgltfmateriallist.cpp (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp new file mode 100644 index 0000000000..7ecbc6eeac --- /dev/null +++ b/indra/newview/llgltfmateriallist.cpp @@ -0,0 +1,186 @@ +/** + * @file llgltfmateriallist.cpp + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llgltfmateriallist.h" + +#include "llassetstorage.h" +#include "llfilesystem.h" +#include "llsdserialize.h" + +#include "tinygltf/tiny_gltf.h" +#include + +LLGLTFMaterialList gGLTFMaterialList; + +static LLColor4 get_color(const std::vector& in) +{ + LLColor4 out; + for (S32 i = 0; i < llmin((S32)in.size(), 4); ++i) + { + out.mV[i] = in[i]; + } + + return out; +} + +static void set_from_model(LLGLTFMaterial* mat, tinygltf::Model& model) +{ + + S32 index; + + auto& material_in = model.materials[0]; + + // get albedo texture + index = material_in.pbrMetallicRoughness.baseColorTexture.index; + if (index >= 0) + { + mat->mAlbedoId.set(model.images[index].uri); + } + else + { + mat->mAlbedoId.setNull(); + } + + // get normal map + index = material_in.normalTexture.index; + if (index >= 0) + { + mat->mNormalId.set(model.images[index].uri); + } + else + { + mat->mNormalId.setNull(); + } + + // get metallic-roughness texture + index = material_in.pbrMetallicRoughness.metallicRoughnessTexture.index; + if (index >= 0) + { + mat->mMetallicRoughnessId.set(model.images[index].uri); + } + else + { + mat->mMetallicRoughnessId.setNull(); + } + + // get emissive texture + index = material_in.emissiveTexture.index; + if (index >= 0) + { + mat->mEmissiveId.set(model.images[index].uri); + } + else + { + mat->mEmissiveId.setNull(); + } + + mat->setAlphaMode(material_in.alphaMode); + mat->mAlphaCutoff = material_in.alphaCutoff; + + mat->mAlbedoColor = get_color(material_in.pbrMetallicRoughness.baseColorFactor); + mat->mEmissiveColor = get_color(material_in.emissiveFactor); + + mat->mMetallicFactor = material_in.pbrMetallicRoughness.metallicFactor; + mat->mRoughnessFactor = material_in.pbrMetallicRoughness.roughnessFactor; + + mat->mDoubleSided = material_in.doubleSided; +} + +LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) +{ + List::iterator iter = mList.find(id); + if (iter == mList.end()) + { + LLGLTFMaterial* mat = new LLGLTFMaterial(); + mList[id] = mat; + + mat->ref(); + + gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, + [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) + { + if (status) + { + LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; + } + + LLFileSystem file(id, asset_type, LLFileSystem::READ); + + std::vector buffer; + buffer.resize(file.getSize()); + file.read((U8*)&buffer[0], buffer.size()); + + LLSD asset; + + // read file into buffer + std::istrstream str(&buffer[0], buffer.size()); + + if (LLSDSerialize::deserialize(asset, str, buffer.size())) + { + if (asset.has("version") && asset["version"] == "1.0") + { + if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") + { + if (asset.has("data") && asset["data"].isString()) + { + std::string data = asset["data"]; + + tinygltf::TinyGLTF gltf; + tinygltf::TinyGLTF loader; + std::string error_msg; + std::string warn_msg; + + tinygltf::Model model_in; + + if (loader.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, data.c_str(), data.length(), "")) + { + set_from_model(mat, model_in); + } + else + { + LL_WARNS() << "Failed to decode material asset: " << LL_ENDL; + LL_WARNS() << warn_msg << LL_ENDL; + LL_WARNS() << error_msg << LL_ENDL; + } + } + } + } + } + else + { + LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; + } + + mat->unref(); + }, nullptr); + + return mat; + } + + return iter->second; +} + -- cgit v1.2.3 From 3e7946bbbf905418595b0632388fb3de4d673312 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 5 Aug 2022 23:36:13 +0300 Subject: SL-17888 Clamp some gltf material values --- indra/newview/llgltfmateriallist.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 7ecbc6eeac..96c29d7ed2 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -99,13 +99,13 @@ static void set_from_model(LLGLTFMaterial* mat, tinygltf::Model& model) } mat->setAlphaMode(material_in.alphaMode); - mat->mAlphaCutoff = material_in.alphaCutoff; + mat->mAlphaCutoff = llclamp((F32)material_in.alphaCutoff, 0.f, 1.f); mat->mAlbedoColor = get_color(material_in.pbrMetallicRoughness.baseColorFactor); mat->mEmissiveColor = get_color(material_in.emissiveFactor); - mat->mMetallicFactor = material_in.pbrMetallicRoughness.metallicFactor; - mat->mRoughnessFactor = material_in.pbrMetallicRoughness.roughnessFactor; + mat->mMetallicFactor = llclamp((F32)material_in.pbrMetallicRoughness.metallicFactor, 0.f, 1.f); + mat->mRoughnessFactor = llclamp((F32)material_in.pbrMetallicRoughness.roughnessFactor, 0.f, 1.f); mat->mDoubleSided = material_in.doubleSided; } -- cgit v1.2.3 From 4bb419031c130402a5589ff698e28e230a0c123a Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 19 Aug 2022 01:45:47 +0300 Subject: SL-17653 Basic local gltf materials --- indra/newview/llgltfmateriallist.cpp | 87 +++++------------------------------- 1 file changed, 12 insertions(+), 75 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 96c29d7ed2..af00cdd05f 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -30,86 +30,13 @@ #include "llassetstorage.h" #include "llfilesystem.h" #include "llsdserialize.h" +#include "lltinygltfhelper.h" #include "tinygltf/tiny_gltf.h" #include LLGLTFMaterialList gGLTFMaterialList; -static LLColor4 get_color(const std::vector& in) -{ - LLColor4 out; - for (S32 i = 0; i < llmin((S32)in.size(), 4); ++i) - { - out.mV[i] = in[i]; - } - - return out; -} - -static void set_from_model(LLGLTFMaterial* mat, tinygltf::Model& model) -{ - - S32 index; - - auto& material_in = model.materials[0]; - - // get albedo texture - index = material_in.pbrMetallicRoughness.baseColorTexture.index; - if (index >= 0) - { - mat->mAlbedoId.set(model.images[index].uri); - } - else - { - mat->mAlbedoId.setNull(); - } - - // get normal map - index = material_in.normalTexture.index; - if (index >= 0) - { - mat->mNormalId.set(model.images[index].uri); - } - else - { - mat->mNormalId.setNull(); - } - - // get metallic-roughness texture - index = material_in.pbrMetallicRoughness.metallicRoughnessTexture.index; - if (index >= 0) - { - mat->mMetallicRoughnessId.set(model.images[index].uri); - } - else - { - mat->mMetallicRoughnessId.setNull(); - } - - // get emissive texture - index = material_in.emissiveTexture.index; - if (index >= 0) - { - mat->mEmissiveId.set(model.images[index].uri); - } - else - { - mat->mEmissiveId.setNull(); - } - - mat->setAlphaMode(material_in.alphaMode); - mat->mAlphaCutoff = llclamp((F32)material_in.alphaCutoff, 0.f, 1.f); - - mat->mAlbedoColor = get_color(material_in.pbrMetallicRoughness.baseColorFactor); - mat->mEmissiveColor = get_color(material_in.emissiveFactor); - - mat->mMetallicFactor = llclamp((F32)material_in.pbrMetallicRoughness.metallicFactor, 0.f, 1.f); - mat->mRoughnessFactor = llclamp((F32)material_in.pbrMetallicRoughness.roughnessFactor, 0.f, 1.f); - - mat->mDoubleSided = material_in.doubleSided; -} - LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { List::iterator iter = mList.find(id); @@ -158,7 +85,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) if (loader.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, data.c_str(), data.length(), "")) { - set_from_model(mat, model_in); + LLTinyGLTFHelper::setFromModel(mat, model_in); } else { @@ -184,3 +111,13 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) return iter->second; } +void LLGLTFMaterialList::addMaterial(const LLUUID& id, LLGLTFMaterial* material) +{ + mList[id] = material; +} + +void LLGLTFMaterialList::removeMaterial(const LLUUID& id) +{ + mList.erase(id); +} + -- cgit v1.2.3 From cf8e1b2ac4614c0b4f8211f980214f5e823a672c Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 2 Sep 2022 16:01:38 -0700 Subject: SL-17967 - do not crash on zero-sized materials --- indra/newview/llgltfmateriallist.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index af00cdd05f..b2d223a3e8 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -56,9 +56,16 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) } LLFileSystem file(id, asset_type, LLFileSystem::READ); + auto size = file.getSize(); + if (!size) + { + LL_DEBUGS() << "Zero size material." << LL_ENDL; + mat->unref(); + return; + } std::vector buffer; - buffer.resize(file.getSize()); + buffer.resize(size); file.read((U8*)&buffer[0], buffer.size()); LLSD asset; -- cgit v1.2.3 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/llgltfmateriallist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index b2d223a3e8..5cbf853179 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -92,7 +92,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) if (loader.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, data.c_str(), data.length(), "")) { - LLTinyGLTFHelper::setFromModel(mat, model_in); + LLTinyGLTFHelper::setFromModel(mat, model_in, 0); } else { -- cgit v1.2.3 From 7a3ed9dadc116e73349ec6fcd37eb3aee5916676 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Fri, 14 Oct 2022 14:33:18 -0700 Subject: Added stub handler for GLTF LargeGenericMessage as part of work on SL-18105 SL-17697 and SL-17698 --- indra/newview/llgltfmateriallist.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 5cbf853179..9c71f11bbc 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -28,13 +28,36 @@ #include "llgltfmateriallist.h" #include "llassetstorage.h" +#include "lldispatcher.h" #include "llfilesystem.h" #include "llsdserialize.h" #include "lltinygltfhelper.h" +#include "llviewergenericmessage.h" #include "tinygltf/tiny_gltf.h" #include +namespace +{ + class LLGLTFOverrideDispatchHandler : public LLDispatchHandler + { + public: + LLGLTFOverrideDispatchHandler() = default; + ~LLGLTFOverrideDispatchHandler() override = default; + + bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override + { + LL_DEBUGS() << "strings: "; + for (std::string const & s : strings) { + LL_CONT << " " << s; + } + LL_CONT << LL_ENDL; + return true; + } + }; + LLGLTFOverrideDispatchHandler handle_gltf_override_message; +} + LLGLTFMaterialList gGLTFMaterialList; LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) @@ -128,3 +151,8 @@ void LLGLTFMaterialList::removeMaterial(const LLUUID& id) mList.erase(id); } +// static +void LLGLTFMaterialList::registerCallbacks() +{ + gGenericDispatcher.addHandler("GLTF", &handle_gltf_override_message); +} -- cgit v1.2.3 From f6762c3de57434730a2cbf6d0241bf1db5c9346c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 14 Oct 2022 17:35:48 -0500 Subject: SL-18105 Add to/from json capability to LLGLTFMaterial --- indra/newview/llgltfmateriallist.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 5cbf853179..a5d2be2d4e 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -83,18 +83,9 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { std::string data = asset["data"]; - tinygltf::TinyGLTF gltf; - tinygltf::TinyGLTF loader; - std::string error_msg; - std::string warn_msg; + std::string warn_msg, error_msg; - tinygltf::Model model_in; - - if (loader.LoadASCIIFromString(&model_in, &error_msg, &warn_msg, data.c_str(), data.length(), "")) - { - LLTinyGLTFHelper::setFromModel(mat, model_in, 0); - } - else + if (!mat->fromJSON(data, warn_msg, error_msg)) { LL_WARNS() << "Failed to decode material asset: " << LL_ENDL; LL_WARNS() << warn_msg << LL_ENDL; -- cgit v1.2.3 From 53e5216b2092b98d6973c2b27c5c75713ec99e73 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Mon, 17 Oct 2022 15:44:32 -0700 Subject: Continuing work on SL-17697 Live editing with material overrides. * Fixed Selection usage so material editor no longer hardcoded to a single object/face * made local preview hack the fallback for when the ModifyMaterialParams cap is missing --- indra/newview/llgltfmateriallist.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 24fd623231..a433644e0e 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -47,11 +47,22 @@ namespace bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override { - LL_DEBUGS() << "strings: "; for (std::string const & s : strings) { - LL_CONT << " " << s; + LL_DEBUGS() << "received override: " << s << LL_ENDL; + +#if 0 + // for now messages are coming in llsd + LLSD override_data; + std::istringstream input(s); + LLSDSerialize::deserialize(override_data, input, s.length()); + LL_DEBUGS() << "deserialized override: " << override_data << LL_ENDL; +#else + std::string warn_msg, error_msg; + LLGLTFMaterial override_data; + override_data.fromJSON(s, warn_msg, error_msg); +#endif } - LL_CONT << LL_ENDL; + return true; } }; -- cgit v1.2.3 From 58472180696401155159414c20a307cf97f7df44 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 19 Oct 2022 00:08:27 +0300 Subject: SL-18391 Basic GLTF lifetime management --- indra/newview/llgltfmateriallist.cpp | 82 ++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 8 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index a433644e0e..84cf746198 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -29,9 +29,11 @@ #include "llassetstorage.h" #include "lldispatcher.h" +#include "llfetchedgltfmaterial.h" #include "llfilesystem.h" #include "llsdserialize.h" #include "lltinygltfhelper.h" +#include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "tinygltf/tiny_gltf.h" @@ -73,19 +75,25 @@ LLGLTFMaterialList gGLTFMaterialList; LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { - List::iterator iter = mList.find(id); + uuid_mat_map_t::iterator iter = mList.find(id); if (iter == mList.end()) { - LLGLTFMaterial* mat = new LLGLTFMaterial(); + LLFetchedGLTFMaterial* mat = new LLFetchedGLTFMaterial(); mList[id] = mat; - mat->ref(); - - gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, - [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) + if (!mat->mFetching) + { + // if we do multiple getAssetData calls, + // some will get distched, messing ref counter + // Todo: get rid of mat->ref() + mat->mFetching = true; + mat->ref(); + + gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, + [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) { if (status) - { + { LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; } @@ -94,6 +102,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) if (!size) { LL_DEBUGS() << "Zero size material." << LL_ENDL; + mat->mFetching = false; mat->unref(); return; } @@ -134,8 +143,10 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; } + mat->mFetching = false; mat->unref(); }, nullptr); + } return mat; } @@ -143,7 +154,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) return iter->second; } -void LLGLTFMaterialList::addMaterial(const LLUUID& id, LLGLTFMaterial* material) +void LLGLTFMaterialList::addMaterial(const LLUUID& id, LLFetchedGLTFMaterial* material) { mList[id] = material; } @@ -153,6 +164,61 @@ void LLGLTFMaterialList::removeMaterial(const LLUUID& id) mList.erase(id); } +void LLGLTFMaterialList::flushMaterials() +{ + // Similar variant to what textures use + static const S32 MIN_UPDATE_COUNT = gSavedSettings.getS32("TextureFetchUpdateMinCount"); // default: 32 + //update MIN_UPDATE_COUNT or 5% of materials, whichever is greater + U32 update_count = llmax((U32)MIN_UPDATE_COUNT, (U32)mList.size() / 20); + update_count = llmin(update_count, (U32)mList.size()); + + const F64 MAX_INACTIVE_TIME = 30.f; + F64 cur_time = LLTimer::getTotalSeconds(); + + uuid_mat_map_t::iterator iter = mList.upper_bound(mLastUpdateKey); + while (update_count-- > 0) + { + if (iter == mList.end()) + { + iter = mList.begin(); + } + + LLPointer material = iter->second; + if (material->getNumRefs() == 2) // this one plus one from the list + { + + if (!material->mActive + && cur_time > material->mExpectedFlusTime) + { + iter = mList.erase(iter); + } + else + { + if (material->mActive) + { + material->mExpectedFlusTime = cur_time + MAX_INACTIVE_TIME; + material->mActive = false; + } + ++iter; + } + } + else + { + material->mActive = true; + ++iter; + } + } + + if (iter != mList.end()) + { + mLastUpdateKey = iter->first; + } + else + { + mLastUpdateKey.setNull(); + } +} + // static void LLGLTFMaterialList::registerCallbacks() { -- cgit v1.2.3 From f575c139300a6c53fa13dd0d7cbfbaa739e2b4b0 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Tue, 18 Oct 2022 21:01:38 -0700 Subject: Better fix for mac/xcode compatibility problem in SL-18391. Keep using unordered_map --- indra/newview/llgltfmateriallist.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 84cf746198..0fd5f37b51 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -175,7 +175,12 @@ void LLGLTFMaterialList::flushMaterials() const F64 MAX_INACTIVE_TIME = 30.f; F64 cur_time = LLTimer::getTotalSeconds(); - uuid_mat_map_t::iterator iter = mList.upper_bound(mLastUpdateKey); + // advance iter one past the last key we updated + uuid_mat_map_t::iterator iter = mList.find(mLastUpdateKey); + if (iter != mList.end()) { + ++iter; + } + while (update_count-- > 0) { if (iter == mList.end()) -- cgit v1.2.3 From d0c2c862efe2ce684b48092465cc753b3ab64da9 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Wed, 19 Oct 2022 09:18:24 -0700 Subject: SL-18105 viewer side for handling Material Override LargeGenericMessage LLGLTFMaterialList now decodes gltf json overrides from the server and stores them in LLTextureEntry::mGLTFMaterialOverrides --- indra/newview/llgltfmateriallist.cpp | 55 +++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 0fd5f37b51..9c04ef4c38 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -35,36 +35,65 @@ #include "lltinygltfhelper.h" #include "llviewercontrol.h" #include "llviewergenericmessage.h" +#include "llviewerobjectlist.h" #include "tinygltf/tiny_gltf.h" #include +#include "json/reader.h" +#include "json/value.h" + namespace { class LLGLTFOverrideDispatchHandler : public LLDispatchHandler { + LOG_CLASS(LLGLTFOverrideDispatchHandler); public: LLGLTFOverrideDispatchHandler() = default; ~LLGLTFOverrideDispatchHandler() override = default; bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override { - for (std::string const & s : strings) { - LL_DEBUGS() << "received override: " << s << LL_ENDL; - -#if 0 - // for now messages are coming in llsd - LLSD override_data; - std::istringstream input(s); - LLSDSerialize::deserialize(override_data, input, s.length()); - LL_DEBUGS() << "deserialized override: " << override_data << LL_ENDL; -#else + // iterate over pairs of parameters + int i; + for (i = 0; i+1 < strings.size(); i += 2) + { + std::string params_json = strings[i]; + std::string override_json = strings[i+1]; + + LL_DEBUGS() << "received override: " << params_json << " | " << override_json << LL_ENDL; + + Json::Value params; + Json::Reader reader; + bool success = reader.parse(params_json, params); + if (!success) + { + LL_WARNS() << "failed to parse override parameters. errors: " << reader.getFormatedErrorMessages() << LL_ENDL; + break; + } + + LLViewerObject * obj = gObjectList.findObject(LLUUID(params["object_id"].asString())); + S32 side = params["side"].asInt(); + std::string warn_msg, error_msg; - LLGLTFMaterial override_data; - override_data.fromJSON(s, warn_msg, error_msg); -#endif + LLPointer override_data = new LLGLTFMaterial(); + success = override_data->fromJSON(override_json, warn_msg, error_msg); +// if (!success) +// { +// LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; +// break; +// } + + if(obj) + { + obj->getTE(side)->setGLTFMaterialOverride(override_data); + } + + LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL; } + LL_WARNS_IF(i != strings.size()) << "parse error or unhandled mismatched odd number of parameters for material override" << LL_ENDL; + return true; } }; -- cgit v1.2.3 From 8741c05cc10d3f39f272bb4739e7313309539d07 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 19 Oct 2022 17:23:54 -0500 Subject: SL-18105 Hook up TE override material to render pipe by way of render material. --- indra/newview/llgltfmateriallist.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 9c04ef4c38..86f4faa9d0 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -36,6 +36,7 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" +#include "pipeline.h" #include "tinygltf/tiny_gltf.h" #include @@ -86,7 +87,10 @@ namespace if(obj) { - obj->getTE(side)->setGLTFMaterialOverride(override_data); + if (obj->setTEGLTFMaterialOverride(side, override_data)) + { + gPipeline.markTextured(obj->mDrawable); + } } LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL; -- cgit v1.2.3 From 40695bbd316ceb15db2c3eb203cbe35188a00aa9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 20 Oct 2022 13:55:42 -0500 Subject: SL-18105 Fix for overrides not showing until a forced mesh update. --- indra/newview/llgltfmateriallist.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 86f4faa9d0..0a104d1db5 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -36,7 +36,6 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" -#include "pipeline.h" #include "tinygltf/tiny_gltf.h" #include @@ -87,10 +86,7 @@ namespace if(obj) { - if (obj->setTEGLTFMaterialOverride(side, override_data)) - { - gPipeline.markTextured(obj->mDrawable); - } + obj->setTEGLTFMaterialOverride(side, override_data); } LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL; -- cgit v1.2.3 From 61967623baaa8988f4f8b48043f79be29452ca80 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 21 Oct 2022 16:34:14 -0500 Subject: SL-18105 Clean up class1/deferred/materialF.glsl (merge cleanup), make override messaging LLSD where it ought to be and JSON where it ought to be. --- indra/newview/llgltfmateriallist.cpp | 72 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 37 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 0a104d1db5..88923ba734 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -45,59 +45,57 @@ namespace { - class LLGLTFOverrideDispatchHandler : public LLDispatchHandler + class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler { - LOG_CLASS(LLGLTFOverrideDispatchHandler); + LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler); public: - LLGLTFOverrideDispatchHandler() = default; - ~LLGLTFOverrideDispatchHandler() override = default; + LLGLTFMaterialOverrideDispatchHandler() = default; + ~LLGLTFMaterialOverrideDispatchHandler() override = default; bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override { - // iterate over pairs of parameters - int i; - for (i = 0; i+1 < strings.size(); i += 2) - { - std::string params_json = strings[i]; - std::string override_json = strings[i+1]; + // receive override data from simulator via LargeGenericMessage + // message should have: + // object_id - UUID of LLViewerObject + // side - S32 index of texture entry + // gltf_json - String of GLTF json for override data + - LL_DEBUGS() << "received override: " << params_json << " | " << override_json << LL_ENDL; + LLSD message; - Json::Value params; - Json::Reader reader; - bool success = reader.parse(params_json, params); - if (!success) + sparam_t::const_iterator it = strings.begin(); + if (it != strings.end()) { + const std::string& llsdRaw = *it++; + std::istringstream llsdData(llsdRaw); + if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length())) { - LL_WARNS() << "failed to parse override parameters. errors: " << reader.getFormatedErrorMessages() << LL_ENDL; - break; + LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } - - LLViewerObject * obj = gObjectList.findObject(LLUUID(params["object_id"].asString())); - S32 side = params["side"].asInt(); - - std::string warn_msg, error_msg; - LLPointer override_data = new LLGLTFMaterial(); - success = override_data->fromJSON(override_json, warn_msg, error_msg); -// if (!success) -// { -// LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; -// break; -// } - - if(obj) + } + + LLViewerObject * obj = gObjectList.findObject(message["object_id"].asUUID()); + S32 side = message["side"].asInteger(); + std::string gltf_json = message["gltf_json"].asString(); + + std::string warn_msg, error_msg; + LLPointer override_data = new LLGLTFMaterial(); + bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + if (!success) + { + LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + } + else + { + if (obj) { obj->setTEGLTFMaterialOverride(side, override_data); } - - LL_DEBUGS() << "successfully parsed override: " << override_data->asJSON() << LL_ENDL; } - LL_WARNS_IF(i != strings.size()) << "parse error or unhandled mismatched odd number of parameters for material override" << LL_ENDL; - return true; } }; - LLGLTFOverrideDispatchHandler handle_gltf_override_message; + LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message; } LLGLTFMaterialList gGLTFMaterialList; @@ -256,5 +254,5 @@ void LLGLTFMaterialList::flushMaterials() // static void LLGLTFMaterialList::registerCallbacks() { - gGenericDispatcher.addHandler("GLTF", &handle_gltf_override_message); + gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message); } -- cgit v1.2.3 From 88659e9fe793a02fb4edcbf8ef07307c25119604 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 22 Oct 2022 15:25:03 -0500 Subject: SL-18105 When saving an object's material to inventory, save the version that as overrides applied. --- indra/newview/llgltfmateriallist.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 88923ba734..4861c2a33b 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -74,6 +74,7 @@ namespace } LLViewerObject * obj = gObjectList.findObject(message["object_id"].asUUID()); + llassert(obj); // should never get an override for an object we don't know about S32 side = message["side"].asInteger(); std::string gltf_json = message["gltf_json"].asString(); -- cgit v1.2.3 From 5c86ec6a6130bef9348d6155c6a7404914c20418 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 24 Oct 2022 16:26:42 -0500 Subject: SL-18105 Add mechanism for applying overrides that were received before associated ViewerObject was ready to receive them. --- indra/newview/llgltfmateriallist.cpp | 49 ++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 4861c2a33b..cd60d34d2f 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -43,6 +43,8 @@ #include "json/reader.h" #include "json/value.h" +LLGLTFMaterialList gGLTFMaterialList; + namespace { class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler @@ -72,24 +74,27 @@ namespace LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } } + + LLUUID object_id = message["object_id"].asUUID(); - LLViewerObject * obj = gObjectList.findObject(message["object_id"].asUUID()); - llassert(obj); // should never get an override for an object we don't know about + LLViewerObject * obj = gObjectList.findObject(object_id); S32 side = message["side"].asInteger(); std::string gltf_json = message["gltf_json"].asString(); std::string warn_msg, error_msg; LLPointer override_data = new LLGLTFMaterial(); bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + if (!success) { LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; } else { - if (obj) + if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) { - obj->setTEGLTFMaterialOverride(side, override_data); + // object not ready to receive override data, queue for later + gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); } } @@ -99,7 +104,41 @@ namespace LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message; } -LLGLTFMaterialList gGLTFMaterialList; +void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFMaterial* override_data) +{ + override_list_t& overrides = mQueuedOverrides[id]; + + if (overrides.size() < side + 1) + { + overrides.resize(side + 1); + } + + overrides[side] = override_data; +} + +void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) +{ + const LLUUID& id = obj->getID(); + auto& iter = mQueuedOverrides.find(id); + + if (iter != mQueuedOverrides.end()) + { + override_list_t& overrides = iter->second; + for (int i = 0; i < overrides.size(); ++i) + { + if (overrides[i].notNull()) + { + if (!obj->getTE(i)->getGLTFMaterial()) + { // object doesn't have its base GLTF material yet, don't apply override (yet) + return; + } + obj->setTEGLTFMaterialOverride(i, overrides[i]); + } + } + + mQueuedOverrides.erase(iter); + } +} LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { -- cgit v1.2.3 From caed8871abd896775e0598641dca07e92dd895e7 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Tue, 25 Oct 2022 10:11:21 -0700 Subject: Xcode build fixes for DRTVWR-559 --- indra/newview/llgltfmateriallist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index cd60d34d2f..05ed7a2019 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -119,7 +119,7 @@ void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFM void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) { const LLUUID& id = obj->getID(); - auto& iter = mQueuedOverrides.find(id); + auto iter = mQueuedOverrides.find(id); if (iter != mQueuedOverrides.end()) { -- cgit v1.2.3 From 8f47657d646c06dbba8d44497c0f81fd00730cc8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 26 Oct 2022 16:08:28 -0500 Subject: SL-18443 Allow nulling out of override data and implement new override message protocol. --- indra/newview/llgltfmateriallist.cpp | 116 ++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 16 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index cd60d34d2f..3b4e9406bb 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -36,13 +36,15 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" - +#include "llcorehttputil.h" #include "tinygltf/tiny_gltf.h" #include #include "json/reader.h" #include "json/value.h" +#include + LLGLTFMaterialList gGLTFMaterialList; namespace @@ -77,27 +79,80 @@ namespace LLUUID object_id = message["object_id"].asUUID(); - LLViewerObject * obj = gObjectList.findObject(object_id); - S32 side = message["side"].asInteger(); - std::string gltf_json = message["gltf_json"].asString(); - - std::string warn_msg, error_msg; - LLPointer override_data = new LLGLTFMaterial(); - bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later + bool clear_all = true; - if (!success) + if (message.has("sides") && message.has("gltf_json")) { - LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + LLSD& sides = message["sides"]; + LLSD& gltf_json = message["gltf_json"]; + + if (sides.isArray() && gltf_json.isArray() && + sides.size() != 0 && + sides.size() == gltf_json.size()) + { + clear_all = false; + + // message should be interpreted thusly: + /// sides is a list of face indices + // gltf_json is a list of corresponding json + // any side not represented in "sides" has no override + + // parse json + std::unordered_set side_set; + + for (int i = 0; i < sides.size(); ++i) + { + LLPointer override_data = new LLGLTFMaterial(); + + std::string gltf_json = message["gltf_json"][i].asString(); + + std::string warn_msg, error_msg; + + bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + + if (!success) + { + LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + } + else + { + S32 side = sides[i].asInteger(); + // flag this side to not be nulled out later + side_set.insert(sides); + + if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + { + // object not ready to receive override data, queue for later + gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); + } + } + } + + if (obj && side_set.size() != obj->getNumTEs()) + { // object exists and at least one texture entry needs to have its override data nulled out + for (int i = 0; i < obj->getNumTEs(); ++i) + { + if (side_set.find(i) == side_set.end()) + { + obj->setTEGLTFMaterialOverride(i, nullptr); + } + } + } + } + else + { + LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL; + } } - else - { - if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + + if (clear_all && obj) + { // override list was empty or an error occurred, null out all overrides for this object + for (int i = 0; i < obj->getNumTEs(); ++i) { - // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); + obj->setTEGLTFMaterialOverride(i, nullptr); } } - return true; } }; @@ -296,3 +351,32 @@ void LLGLTFMaterialList::registerCallbacks() { gGenericDispatcher.addHandler("GLTFMaterialOverride", &handle_gltf_override_message); } + +// static +void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides) +{ + LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("modifyMaterialCoro", httpPolicy)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + LLCore::HttpHeaders::ptr_t httpHeaders; + + httpOpts->setFollowRedirects(true); + + LL_DEBUGS() << "Applying override via ModifyMaterialParams cap: " << overrides << LL_ENDL; + + LLSD result = httpAdapter->postAndSuspend(httpRequest, cap_url, overrides, httpOpts, httpHeaders); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + LL_WARNS() << "Failed to modify material." << LL_ENDL; + } + else if (!result["success"].asBoolean()) + { + LL_WARNS() << "Failed to modify material: " << result["message"] << LL_ENDL; + } +} -- cgit v1.2.3 From a6da63020729f5e1f2163442fba69a46b04a9289 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 26 Oct 2022 23:02:49 -0500 Subject: SL-18469 Fix for material edits only applying to one face. --- indra/newview/llgltfmateriallist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 8210efae96..48f4305ee7 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -119,7 +119,7 @@ namespace { S32 side = sides[i].asInteger(); // flag this side to not be nulled out later - side_set.insert(sides); + side_set.insert(sides[i]); if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) { -- cgit v1.2.3 From 6d0fcc0e616ff58f4a83bc3730374c5509ee959a Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 28 Oct 2022 19:58:27 +0300 Subject: SL-17699 Blank material Id for material picker --- indra/newview/llgltfmateriallist.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 48f4305ee7..ab7a6495c4 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -47,6 +47,8 @@ LLGLTFMaterialList gGLTFMaterialList; +const LLUUID LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID("968cbad0-4dad-d64e-71b5-72bf13ad051a"); + namespace { class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler -- cgit v1.2.3 From 35d4124b5eb3d412643124993b4fa8c09f3f747c Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Sat, 29 Oct 2022 03:16:16 +0300 Subject: SL-18446 Material override arrival for selected objects should update material editor --- indra/newview/llgltfmateriallist.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index ab7a6495c4..80f198fc6c 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -31,6 +31,7 @@ #include "lldispatcher.h" #include "llfetchedgltfmaterial.h" #include "llfilesystem.h" +#include "llmaterialeditor.h" #include "llsdserialize.h" #include "lltinygltfhelper.h" #include "llviewercontrol.h" @@ -128,6 +129,12 @@ namespace // object not ready to receive override data, queue for later gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); } + else if (obj && obj->isAnySelected()) + { + // Might want to cause a full selection + // update here instead of just an editor + LLMaterialEditor::updateLive(); + } } } @@ -140,6 +147,12 @@ namespace obj->setTEGLTFMaterialOverride(i, nullptr); } } + if (obj->isAnySelected()) + { + // Might want to cause a full selection + // update here instead of just an editor + LLMaterialEditor::updateLive(); + } } } else @@ -154,6 +167,12 @@ namespace { obj->setTEGLTFMaterialOverride(i, nullptr); } + if (obj->isAnySelected()) + { + // Might want to cause a full selection + // update here instead of just an editor + LLMaterialEditor::updateLive(); + } } return true; } @@ -190,6 +209,12 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) return; } obj->setTEGLTFMaterialOverride(i, overrides[i]); + if (obj->isAnySelected()) + { + // Might want to cause a full selection + // update here instead of just an editor + LLMaterialEditor::updateLive(); + } } } -- cgit v1.2.3 From 094a8876d6e030b5dc618ea28250e15022030c78 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 31 Oct 2022 20:12:53 +0200 Subject: SL-18446 Material override arrival filtering --- indra/newview/llgltfmateriallist.cpp | 49 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 80f198fc6c..d91a448bc8 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -117,6 +117,12 @@ namespace if (!success) { LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + + // unblock material editor + if (obj && obj->isAnySelected()) + { + LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); + } } else { @@ -131,28 +137,25 @@ namespace } else if (obj && obj->isAnySelected()) { - // Might want to cause a full selection - // update here instead of just an editor - LLMaterialEditor::updateLive(); + LLMaterialEditor::updateLive(object_id, side); } } } if (obj && side_set.size() != obj->getNumTEs()) { // object exists and at least one texture entry needs to have its override data nulled out + bool object_has_selection = obj->isAnySelected(); for (int i = 0; i < obj->getNumTEs(); ++i) { if (side_set.find(i) == side_set.end()) { obj->setTEGLTFMaterialOverride(i, nullptr); + if (object_has_selection) + { + LLMaterialEditor::updateLive(object_id, i); + } } } - if (obj->isAnySelected()) - { - // Might want to cause a full selection - // update here instead of just an editor - LLMaterialEditor::updateLive(); - } } } else @@ -163,15 +166,14 @@ namespace if (clear_all && obj) { // override list was empty or an error occurred, null out all overrides for this object + bool object_has_selection = obj->isAnySelected(); for (int i = 0; i < obj->getNumTEs(); ++i) { obj->setTEGLTFMaterialOverride(i, nullptr); - } - if (obj->isAnySelected()) - { - // Might want to cause a full selection - // update here instead of just an editor - LLMaterialEditor::updateLive(); + if (object_has_selection) + { + LLMaterialEditor::updateLive(obj->getID(), i); + } } } return true; @@ -199,6 +201,7 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) if (iter != mQueuedOverrides.end()) { + bool object_has_selection = obj->isAnySelected(); override_list_t& overrides = iter->second; for (int i = 0; i < overrides.size(); ++i) { @@ -209,11 +212,9 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) return; } obj->setTEGLTFMaterialOverride(i, overrides[i]); - if (obj->isAnySelected()) + if (object_has_selection) { - // Might want to cause a full selection - // update here instead of just an editor - LLMaterialEditor::updateLive(); + LLMaterialEditor::updateLive(id, i); } } } @@ -380,7 +381,7 @@ void LLGLTFMaterialList::registerCallbacks() } // static -void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides) +void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, void(*done_callback)(bool) ) { LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t @@ -398,12 +399,20 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides) LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + bool success = true; if (!status) { LL_WARNS() << "Failed to modify material." << LL_ENDL; + success = false; } else if (!result["success"].asBoolean()) { LL_WARNS() << "Failed to modify material: " << result["message"] << LL_ENDL; + success = false; + } + + if (done_callback) + { + done_callback(success); } } -- cgit v1.2.3 From 9f21fba6d9a28cd1b324a115a0a2f86613a134e7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 1 Nov 2022 08:31:01 -0500 Subject: SL-18513 Put profile markers around GLTF code. --- indra/newview/llgltfmateriallist.cpp | 73 ++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index d91a448bc8..a4033f0d4d 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -61,6 +61,7 @@ namespace bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override { + LL_PROFILE_ZONE_SCOPED; // receive override data from simulator via LargeGenericMessage // message should have: // object_id - UUID of LLViewerObject @@ -196,6 +197,7 @@ void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFM void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) { + LL_PROFILE_ZONE_SCOPED; const LLUUID& id = obj->getID(); auto iter = mQueuedOverrides.find(id); @@ -225,9 +227,11 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { + LL_PROFILE_ZONE_SCOPED; uuid_mat_map_t::iterator iter = mList.find(id); if (iter == mList.end()) { + LL_PROFILE_ZONE_NAMED("gltf fetch") LLFetchedGLTFMaterial* mat = new LLFetchedGLTFMaterial(); mList[id] = mat; @@ -242,55 +246,66 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) { + LL_PROFILE_ZONE_SCOPED("gltf asset callback"); if (status) { LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; } - LLFileSystem file(id, asset_type, LLFileSystem::READ); - auto size = file.getSize(); - if (!size) + std::vector buffer; + { - LL_DEBUGS() << "Zero size material." << LL_ENDL; - mat->mFetching = false; - mat->unref(); - return; - } + LL_PROFILE_ZONE_SCOPED("gltf read asset"); + LLFileSystem file(id, asset_type, LLFileSystem::READ); + auto size = file.getSize(); + if (!size) + { + LL_DEBUGS() << "Zero size material." << LL_ENDL; + mat->mFetching = false; + mat->unref(); + return; + } - std::vector buffer; - buffer.resize(size); - file.read((U8*)&buffer[0], buffer.size()); - LLSD asset; - // read file into buffer - std::istrstream str(&buffer[0], buffer.size()); + buffer.resize(size); + file.read((U8*)&buffer[0], buffer.size()); + } - if (LLSDSerialize::deserialize(asset, str, buffer.size())) { - if (asset.has("version") && asset["version"] == "1.0") + LL_PROFILE_ZONE_SCOPED("gltf deserialize asset"); + + LLSD asset; + + // read file into buffer + std::istrstream str(&buffer[0], buffer.size()); + + if (LLSDSerialize::deserialize(asset, str, buffer.size())) { - if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") + if (asset.has("version") && asset["version"] == "1.0") { - if (asset.has("data") && asset["data"].isString()) + if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") { - std::string data = asset["data"]; + if (asset.has("data") && asset["data"].isString()) + { + std::string data = asset["data"]; - std::string warn_msg, error_msg; + std::string warn_msg, error_msg; - if (!mat->fromJSON(data, warn_msg, error_msg)) - { - LL_WARNS() << "Failed to decode material asset: " << LL_ENDL; - LL_WARNS() << warn_msg << LL_ENDL; - LL_WARNS() << error_msg << LL_ENDL; + if (!mat->fromJSON(data, warn_msg, error_msg)) + { + LL_WARNS() << "Failed to decode material asset: " << LL_ENDL; + LL_WARNS() << warn_msg << LL_ENDL; + LL_WARNS() << error_msg << LL_ENDL; + } } } } } - } - else - { - LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; + else + { + LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; + } } mat->mFetching = false; -- cgit v1.2.3 From a0e7dd45d950eef1c8f6bcc33f4035629189a7b9 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Tue, 1 Nov 2022 10:15:37 -0700 Subject: Fix mac build for DRTVWR-559. PROFILE_ZONE_SCOPED macro cant take an argument --- indra/newview/llgltfmateriallist.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index a4033f0d4d..dabacccf66 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -246,7 +246,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) { - LL_PROFILE_ZONE_SCOPED("gltf asset callback"); + LL_PROFILE_ZONE_NAMED("gltf asset callback"); if (status) { LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; @@ -255,7 +255,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) std::vector buffer; { - LL_PROFILE_ZONE_SCOPED("gltf read asset"); + LL_PROFILE_ZONE_NAMED("gltf read asset"); LLFileSystem file(id, asset_type, LLFileSystem::READ); auto size = file.getSize(); if (!size) @@ -273,7 +273,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) } { - LL_PROFILE_ZONE_SCOPED("gltf deserialize asset"); + LL_PROFILE_ZONE_NAMED("gltf deserialize asset"); LLSD asset; -- cgit v1.2.3 From 40d01ba39388c5400e2582145e77295c51f33fc3 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 8 Nov 2022 12:20:59 -0600 Subject: SL-18585 Batch updates to ModifyMaterialParams capability. --- indra/newview/llgltfmateriallist.cpp | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index dabacccf66..8e184c719d 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -38,6 +38,8 @@ #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" #include "llcorehttputil.h" +#include "llagent.h" + #include "tinygltf/tiny_gltf.h" #include @@ -48,6 +50,8 @@ LLGLTFMaterialList gGLTFMaterialList; +LLGLTFMaterialList::modify_queue_t LLGLTFMaterialList::sModifyQueue; + const LLUUID LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID("968cbad0-4dad-d64e-71b5-72bf13ad051a"); namespace @@ -225,6 +229,48 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) } } +void LLGLTFMaterialList::queueModifyMaterial(const LLUUID& id, S32 side, const LLGLTFMaterial& mat) +{ + sModifyQueue.push_back({ id, side, mat, LLUUID::null, true, false }); +} + +void LLGLTFMaterialList::flushModifyMaterialQueue(void(*done_callback)(bool)) +{ + LLSD data = LLSD::emptyArray(); + + S32 i = 0; + for (auto& e : sModifyQueue) + { + data[i]["object_id"] = e.object_id; + data[i]["side"] = e.side; + + if (e.has_asset_id) + { + data[i]["asset_id"] = e.asset_id; + } + + if (e.has_override) + { + data[i]["gltf_json"] = e.override_data.asJSON(); + } + + ++i; + } + + std::stringstream str; + + LLSDSerialize::serialize(data, str, LLSDSerialize::LLSD_NOTATION, LLSDFormatter::OPTIONS_PRETTY); + LL_INFOS() << "\n" << str.str() << LL_ENDL; + + LLCoros::instance().launch("modifyMaterialCoro", + std::bind(&LLGLTFMaterialList::modifyMaterialCoro, + gAgent.getRegionCapability("ModifyMaterialParams"), + data, + done_callback)); + + sModifyQueue.clear(); +} + LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { LL_PROFILE_ZONE_SCOPED; -- cgit v1.2.3 From a83a4811b51472b5f760861b6a8acde5fc3bd43b Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 9 Nov 2022 22:45:20 +0200 Subject: SL-18518 Move json to material work to background thread --- indra/newview/llgltfmateriallist.cpp | 164 ++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 62 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 8e184c719d..c18988ef15 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -271,92 +271,132 @@ void LLGLTFMaterialList::flushModifyMaterialQueue(void(*done_callback)(bool)) sModifyQueue.clear(); } -LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) +class AssetLoadUserData { - LL_PROFILE_ZONE_SCOPED; - uuid_mat_map_t::iterator iter = mList.find(id); - if (iter == mList.end()) +public: + AssetLoadUserData() {} + tinygltf::Model mModelIn; + LLPointer mMaterial; +}; + +void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) +{ + LL_PROFILE_ZONE_NAMED("gltf asset callback"); + AssetLoadUserData* asset_data = (AssetLoadUserData*)user_data; + + if (status != LL_ERR_NOERR) + { + LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; + asset_data->mMaterial->mFetching = false; + delete asset_data; + } + else { - LL_PROFILE_ZONE_NAMED("gltf fetch") - LLFetchedGLTFMaterial* mat = new LLFetchedGLTFMaterial(); - mList[id] = mat; - if (!mat->mFetching) - { - // if we do multiple getAssetData calls, - // some will get distched, messing ref counter - // Todo: get rid of mat->ref() - mat->mFetching = true; - mat->ref(); + LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); + LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); - gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, - [=](const LLUUID& id, LLAssetType::EType asset_type, void* user_data, S32 status, LLExtStat ext_status) + typedef std::pair return_data_t; + + main_queue->postTo( + general_queue, + [id, asset_type, asset_data]() // Work done on general queue + { + std::vector buffer; { - LL_PROFILE_ZONE_NAMED("gltf asset callback"); - if (status) + LL_PROFILE_ZONE_NAMED("gltf read asset"); + LLFileSystem file(id, asset_type, LLFileSystem::READ); + auto size = file.getSize(); + if (!size) { - LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; + return false; } - std::vector buffer; + buffer.resize(size); + file.read((U8*)&buffer[0], buffer.size()); + } - { - LL_PROFILE_ZONE_NAMED("gltf read asset"); - LLFileSystem file(id, asset_type, LLFileSystem::READ); - auto size = file.getSize(); - if (!size) - { - LL_DEBUGS() << "Zero size material." << LL_ENDL; - mat->mFetching = false; - mat->unref(); - return; - } + { + LL_PROFILE_ZONE_NAMED("gltf deserialize asset"); + LLSD asset; + // read file into buffer + std::istrstream str(&buffer[0], buffer.size()); - buffer.resize(size); - file.read((U8*)&buffer[0], buffer.size()); - } - + if (LLSDSerialize::deserialize(asset, str, buffer.size())) { - LL_PROFILE_ZONE_NAMED("gltf deserialize asset"); - - LLSD asset; - - // read file into buffer - std::istrstream str(&buffer[0], buffer.size()); - - if (LLSDSerialize::deserialize(asset, str, buffer.size())) + if (asset.has("version") && asset["version"] == "1.0") { - if (asset.has("version") && asset["version"] == "1.0") + if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") { - if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") + if (asset.has("data") && asset["data"].isString()) { - if (asset.has("data") && asset["data"].isString()) - { - std::string data = asset["data"]; + std::string data = asset["data"]; + + std::string warn_msg, error_msg; - std::string warn_msg, error_msg; + LL_PROFILE_ZONE_SCOPED; + tinygltf::TinyGLTF gltf; - if (!mat->fromJSON(data, warn_msg, error_msg)) - { - LL_WARNS() << "Failed to decode material asset: " << LL_ENDL; - LL_WARNS() << warn_msg << LL_ENDL; - LL_WARNS() << error_msg << LL_ENDL; - } + if (!gltf.LoadASCIIFromString(&asset_data->mModelIn, &error_msg, &warn_msg, data.c_str(), data.length(), "")) + { + LL_WARNS() << "Failed to decode material asset: " + << LL_NEWLINE + << warn_msg + << LL_NEWLINE + << error_msg + << LL_ENDL; + return false; } + return true; } } } - else - { - LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; - } } + else + { + LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; + } + } + + return false; + }, + [id, asset_data](bool result) // Callback to main thread + mutable { + + if (result) + { + asset_data->mMaterial->setFromModel(asset_data->mModelIn, 0/*only one index*/); + } + else + { + LL_DEBUGS() << "Failed to get material " << id << LL_ENDL; + } + asset_data->mMaterial->mFetching = false; + delete asset_data; + }); + } +} + +LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) +{ + LL_PROFILE_ZONE_SCOPED; + uuid_mat_map_t::iterator iter = mList.find(id); + if (iter == mList.end()) + { + LL_PROFILE_ZONE_NAMED("gltf fetch") + LLFetchedGLTFMaterial* mat = new LLFetchedGLTFMaterial(); + mList[id] = mat; + + if (!mat->mFetching) + { + mat->mFetching = true; + + AssetLoadUserData *user_data = new AssetLoadUserData(); + user_data->mMaterial = mat; - mat->mFetching = false; - mat->unref(); - }, nullptr); + gAssetStorage->getAssetData(id, LLAssetType::AT_MATERIAL, onAssetLoadComplete, (void*)user_data); } return mat; -- cgit v1.2.3 From 1ed8f7cd0ca41ab655aaeeaf141eb4ef20f16bd0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 9 Nov 2022 17:10:31 -0600 Subject: SL-18602 Fix for applying material asset not removing overrides on drag-and-drop --- indra/newview/llgltfmateriallist.cpp | 229 +++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 105 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 8e184c719d..e08a9c2533 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -51,139 +51,141 @@ LLGLTFMaterialList gGLTFMaterialList; LLGLTFMaterialList::modify_queue_t LLGLTFMaterialList::sModifyQueue; +LLGLTFMaterialList::apply_queue_t LLGLTFMaterialList::sApplyQueue; const LLUUID LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID("968cbad0-4dad-d64e-71b5-72bf13ad051a"); -namespace +class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler { - class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler - { - LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler); - public: - LLGLTFMaterialOverrideDispatchHandler() = default; - ~LLGLTFMaterialOverrideDispatchHandler() override = default; + LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler); +public: + LLGLTFMaterialOverrideDispatchHandler() = default; + ~LLGLTFMaterialOverrideDispatchHandler() override = default; - bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override - { - LL_PROFILE_ZONE_SCOPED; - // receive override data from simulator via LargeGenericMessage - // message should have: - // object_id - UUID of LLViewerObject - // side - S32 index of texture entry - // gltf_json - String of GLTF json for override data + bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override + { + LL_PROFILE_ZONE_SCOPED; + // receive override data from simulator via LargeGenericMessage + // message should have: + // object_id - UUID of LLViewerObject + // side - S32 index of texture entry + // gltf_json - String of GLTF json for override data - LLSD message; + LLSD message; - sparam_t::const_iterator it = strings.begin(); - if (it != strings.end()) { - const std::string& llsdRaw = *it++; - std::istringstream llsdData(llsdRaw); - if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length())) - { - LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; - } + sparam_t::const_iterator it = strings.begin(); + if (it != strings.end()) { + const std::string& llsdRaw = *it++; + std::istringstream llsdData(llsdRaw); + if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length())) + { + LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } + } - LLUUID object_id = message["object_id"].asUUID(); + LLUUID object_id = message["object_id"].asUUID(); - LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later - bool clear_all = true; + LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later + bool clear_all = true; - if (message.has("sides") && message.has("gltf_json")) - { - LLSD& sides = message["sides"]; - LLSD& gltf_json = message["gltf_json"]; + if (message.has("sides") && message.has("gltf_json")) + { + LLSD& sides = message["sides"]; + LLSD& gltf_json = message["gltf_json"]; - if (sides.isArray() && gltf_json.isArray() && - sides.size() != 0 && - sides.size() == gltf_json.size()) - { - clear_all = false; + if (sides.isArray() && gltf_json.isArray() && + sides.size() != 0 && + sides.size() == gltf_json.size()) + { + clear_all = false; - // message should be interpreted thusly: - /// sides is a list of face indices - // gltf_json is a list of corresponding json - // any side not represented in "sides" has no override + // message should be interpreted thusly: + /// sides is a list of face indices + // gltf_json is a list of corresponding json + // any side not represented in "sides" has no override - // parse json - std::unordered_set side_set; + // parse json + std::unordered_set side_set; - for (int i = 0; i < sides.size(); ++i) - { - LLPointer override_data = new LLGLTFMaterial(); + for (int i = 0; i < sides.size(); ++i) + { + LLPointer override_data = new LLGLTFMaterial(); - std::string gltf_json = message["gltf_json"][i].asString(); + std::string gltf_json = message["gltf_json"][i].asString(); - std::string warn_msg, error_msg; + std::string warn_msg, error_msg; - bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + + if (!success) + { + LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; - if (!success) + // unblock material editor + if (obj && obj->isAnySelected()) { - LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); + } + } + else + { + S32 side = sides[i].asInteger(); + // flag this side to not be nulled out later + side_set.insert(sides[i]); - // unblock material editor - if (obj && obj->isAnySelected()) - { - LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); - } + if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + { + // object not ready to receive override data, queue for later + gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); } - else + else if (obj && obj->isAnySelected()) { - S32 side = sides[i].asInteger(); - // flag this side to not be nulled out later - side_set.insert(sides[i]); - - if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) - { - // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); - } - else if (obj && obj->isAnySelected()) - { - LLMaterialEditor::updateLive(object_id, side); - } + LLMaterialEditor::updateLive(object_id, side); } } + } - if (obj && side_set.size() != obj->getNumTEs()) - { // object exists and at least one texture entry needs to have its override data nulled out - bool object_has_selection = obj->isAnySelected(); - for (int i = 0; i < obj->getNumTEs(); ++i) + if (obj && side_set.size() != obj->getNumTEs()) + { // object exists and at least one texture entry needs to have its override data nulled out + bool object_has_selection = obj->isAnySelected(); + for (int i = 0; i < obj->getNumTEs(); ++i) + { + if (side_set.find(i) == side_set.end()) { - if (side_set.find(i) == side_set.end()) + obj->setTEGLTFMaterialOverride(i, nullptr); + if (object_has_selection) { - obj->setTEGLTFMaterialOverride(i, nullptr); - if (object_has_selection) - { - LLMaterialEditor::updateLive(object_id, i); - } + LLMaterialEditor::updateLive(object_id, i); } } } } - else - { - LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL; - } } + else + { + LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL; + } + } - if (clear_all && obj) - { // override list was empty or an error occurred, null out all overrides for this object - bool object_has_selection = obj->isAnySelected(); - for (int i = 0; i < obj->getNumTEs(); ++i) + if (clear_all && obj) + { // override list was empty or an error occurred, null out all overrides for this object + bool object_has_selection = obj->isAnySelected(); + for (int i = 0; i < obj->getNumTEs(); ++i) + { + obj->setTEGLTFMaterialOverride(i, nullptr); + if (object_has_selection) { - obj->setTEGLTFMaterialOverride(i, nullptr); - if (object_has_selection) - { - LLMaterialEditor::updateLive(obj->getID(), i); - } + LLMaterialEditor::updateLive(obj->getID(), i); } } - return true; } - }; + return true; + } +}; + +namespace +{ LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message; } @@ -229,12 +231,24 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) } } -void LLGLTFMaterialList::queueModifyMaterial(const LLUUID& id, S32 side, const LLGLTFMaterial& mat) +void LLGLTFMaterialList::queueModifyMaterial(const LLUUID& id, S32 side, const LLGLTFMaterial* mat) { - sModifyQueue.push_back({ id, side, mat, LLUUID::null, true, false }); + if (mat == nullptr) + { + sModifyQueue.push_back({ id, side, LLGLTFMaterial(), false }); + } + else + { + sModifyQueue.push_back({ id, side, *mat, true}); + } } -void LLGLTFMaterialList::flushModifyMaterialQueue(void(*done_callback)(bool)) +void LLGLTFMaterialList::queueApplyMaterialAsset(const LLUUID& object_id, S32 side, const LLUUID& asset_id) +{ + sApplyQueue.push_back({ object_id, side, asset_id}); +} + +void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) { LLSD data = LLSD::emptyArray(); @@ -244,11 +258,6 @@ void LLGLTFMaterialList::flushModifyMaterialQueue(void(*done_callback)(bool)) data[i]["object_id"] = e.object_id; data[i]["side"] = e.side; - if (e.has_asset_id) - { - data[i]["asset_id"] = e.asset_id; - } - if (e.has_override) { data[i]["gltf_json"] = e.override_data.asJSON(); @@ -256,19 +265,29 @@ void LLGLTFMaterialList::flushModifyMaterialQueue(void(*done_callback)(bool)) ++i; } + sModifyQueue.clear(); - std::stringstream str; + for (auto& e : sApplyQueue) + { + data[i]["object_id"] = e.object_id; + data[i]["side"] = e.side; + data[i]["asset_id"] = e.asset_id; + data[i]["gltf_json"] = ""; // null out any existing overrides when applying a material asset + ++i; + } + sApplyQueue.clear(); +#if 0 // debug output of data being sent to capability + std::stringstream str; LLSDSerialize::serialize(data, str, LLSDSerialize::LLSD_NOTATION, LLSDFormatter::OPTIONS_PRETTY); LL_INFOS() << "\n" << str.str() << LL_ENDL; +#endif LLCoros::instance().launch("modifyMaterialCoro", std::bind(&LLGLTFMaterialList::modifyMaterialCoro, gAgent.getRegionCapability("ModifyMaterialParams"), data, done_callback)); - - sModifyQueue.clear(); } LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) -- cgit v1.2.3 From 76de36c40520445d7ad77f85cd6c601942b97032 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 10 Nov 2022 13:21:06 -0600 Subject: SL-18602 Integrate queueModify/queueApply/queueUpdate into all the places that used to post to ModifyMaterialParams directly. --- indra/newview/llgltfmateriallist.cpp | 119 ++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 9 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 36b87b1a3d..2991d26d41 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -52,9 +52,87 @@ LLGLTFMaterialList gGLTFMaterialList; LLGLTFMaterialList::modify_queue_t LLGLTFMaterialList::sModifyQueue; LLGLTFMaterialList::apply_queue_t LLGLTFMaterialList::sApplyQueue; +LLSD LLGLTFMaterialList::sUpdates; const LLUUID LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID("968cbad0-4dad-d64e-71b5-72bf13ad051a"); +// return true if given data is (probably) valid update message for ModifyMaterialParams capability +static bool is_valid_update(const LLSD& data) +{ + llassert(data.isMap()); + + U32 count = 0; + + if (data.has("object_id")) + { + if (!data["object_id"].isUUID()) + { + LL_WARNS() << "object_id is not a UUID" << LL_ENDL; + return false; + } + ++count; + } + else + { + LL_WARNS() << "Missing required parameter: object_id" << LL_ENDL; + return false; + } + + if (data.has("side")) + { + if (!data["side"].isInteger()) + { + LL_WARNS() << "side is not an integer" << LL_ENDL; + return false; + } + + if (data["side"].asInteger() < -1) + { + LL_WARNS() << "side is invalid" << LL_ENDL; + } + ++count; + } + else + { + LL_WARNS() << "Missing required parameter: side" << LL_ENDL; + return false; + } + + if (data.has("gltf_json")) + { + if (!data["gltf_json"].isString()) + { + LL_WARNS() << "gltf_json is not a string" << LL_ENDL; + return false; + } + ++count; + } + + if (data.has("asset_id")) + { + if (!data["asset_id"].isUUID()) + { + LL_WARNS() << "asset_id is not a UUID" << LL_ENDL; + return false; + } + ++count; + } + + if (count < 3) + { + LL_WARNS() << "Only specified object_id and side, update won't actually change anything and is just noise" << LL_ENDL; + return false; + } + + if (data.size() != count) + { + LL_WARNS() << "update data contains unrecognized parameters" << LL_ENDL; + return false; + } + + return true; +} + class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler { LOG_CLASS(LLGLTFMaterialOverrideDispatchHandler); @@ -231,7 +309,7 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) } } -void LLGLTFMaterialList::queueModifyMaterial(const LLUUID& id, S32 side, const LLGLTFMaterial* mat) +void LLGLTFMaterialList::queueModify(const LLUUID& id, S32 side, const LLGLTFMaterial* mat) { if (mat == nullptr) { @@ -243,16 +321,29 @@ void LLGLTFMaterialList::queueModifyMaterial(const LLUUID& id, S32 side, const L } } -void LLGLTFMaterialList::queueApplyMaterialAsset(const LLUUID& object_id, S32 side, const LLUUID& asset_id) +void LLGLTFMaterialList::queueApply(const LLUUID& object_id, S32 side, const LLUUID& asset_id) { sApplyQueue.push_back({ object_id, side, asset_id}); } +void LLGLTFMaterialList::queueUpdate(const LLSD& data) +{ + llassert(is_valid_update(data)); + + if (!sUpdates.isArray()) + { + sUpdates = LLSD::emptyArray(); + } + + sUpdates[sUpdates.size()] = data; +} + void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) { - LLSD data = LLSD::emptyArray(); + LLSD& data = sUpdates; + + S32 i = data.size(); - S32 i = 0; for (auto& e : sModifyQueue) { data[i]["object_id"] = e.object_id; @@ -263,6 +354,7 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) data[i]["gltf_json"] = e.override_data.asJSON(); } + llassert(is_valid_update(data[i])); ++i; } sModifyQueue.clear(); @@ -273,6 +365,8 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) data[i]["side"] = e.side; data[i]["asset_id"] = e.asset_id; data[i]["gltf_json"] = ""; // null out any existing overrides when applying a material asset + + llassert(is_valid_update(data[i])); ++i; } sApplyQueue.clear(); @@ -283,11 +377,18 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) LL_INFOS() << "\n" << str.str() << LL_ENDL; #endif - LLCoros::instance().launch("modifyMaterialCoro", - std::bind(&LLGLTFMaterialList::modifyMaterialCoro, - gAgent.getRegionCapability("ModifyMaterialParams"), - data, - done_callback)); + if (sUpdates.size() > 0) + { + LLCoros::instance().launch("modifyMaterialCoro", + std::bind(&LLGLTFMaterialList::modifyMaterialCoro, + gAgent.getRegionCapability("ModifyMaterialParams"), + sUpdates, + done_callback)); + + sUpdates = LLSD::emptyArray(); + } + + } class AssetLoadUserData -- cgit v1.2.3 From 72884b29e5f84fb13879e826e8b1a3de9ce8fbbc Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 11 Nov 2022 01:10:47 +0200 Subject: mac build fix --- indra/newview/llgltfmateriallist.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 2991d26d41..173e9ebb1d 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -56,6 +56,7 @@ LLSD LLGLTFMaterialList::sUpdates; const LLUUID LLGLTFMaterialList::BLANK_MATERIAL_ASSET_ID("968cbad0-4dad-d64e-71b5-72bf13ad051a"); +#ifdef SHOW_ASSERT // return true if given data is (probably) valid update message for ModifyMaterialParams capability static bool is_valid_update(const LLSD& data) { @@ -132,6 +133,7 @@ static bool is_valid_update(const LLSD& data) return true; } +#endif class LLGLTFMaterialOverrideDispatchHandler : public LLDispatchHandler { -- cgit v1.2.3 From 7c677776801385166fe836857ca597a130dbda33 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 11 Nov 2022 22:35:41 +0200 Subject: SL-18518 Move 'json to override' work to background thread --- indra/newview/llgltfmateriallist.cpp | 129 ++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 49 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 173e9ebb1d..206be33051 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -163,67 +163,102 @@ public: LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } } + + LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); + LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); - LLUUID object_id = message["object_id"].asUUID(); - - LLViewerObject * obj = gObjectList.findObject(object_id); // NOTE: null object here does NOT mean nothing to do, parse message and queue results for later - bool clear_all = true; + struct ReturnData + { + public: + std::vector > mMaterialVector; + std::vector mResults; + }; - if (message.has("sides") && message.has("gltf_json")) + // fromJson() is performance heavy offload to a thread. + main_queue->postTo( + general_queue, + [message]() // Work done on general queue { - LLSD& sides = message["sides"]; - LLSD& gltf_json = message["gltf_json"]; + ReturnData result; - if (sides.isArray() && gltf_json.isArray() && - sides.size() != 0 && - sides.size() == gltf_json.size()) + if (message.has("sides") && message.has("gltf_json")) { - clear_all = false; + LLSD& sides = message.get("sides"); + LLSD& gltf_json = message.get("gltf_json"); - // message should be interpreted thusly: - /// sides is a list of face indices - // gltf_json is a list of corresponding json - // any side not represented in "sides" has no override + if (sides.isArray() && gltf_json.isArray() && + sides.size() != 0 && + sides.size() == gltf_json.size()) + { + // message should be interpreted thusly: + /// sides is a list of face indices + // gltf_json is a list of corresponding json + // any side not represented in "sides" has no override + result.mResults.resize(sides.size()); + result.mMaterialVector.resize(sides.size()); + + // parse json + for (int i = 0; i < sides.size(); ++i) + { + LLPointer override_data = new LLGLTFMaterial(); - // parse json - std::unordered_set side_set; + std::string gltf_json_str = gltf_json[i].asString(); - for (int i = 0; i < sides.size(); ++i) - { - LLPointer override_data = new LLGLTFMaterial(); - - std::string gltf_json = message["gltf_json"][i].asString(); + std::string warn_msg, error_msg; - std::string warn_msg, error_msg; - - bool success = override_data->fromJSON(gltf_json, warn_msg, error_msg); + bool success = override_data->fromJSON(gltf_json_str, warn_msg, error_msg); - if (!success) - { - LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + result.mResults[i] = success; - // unblock material editor - if (obj && obj->isAnySelected()) + if (success) { - LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); + result.mMaterialVector[i] = override_data; + } + else + { + LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; } } - else + } + } + return result; + }, + [message](ReturnData result) // Callback to main thread + mutable { + + LLUUID object_id = message["object_id"].asUUID(); + LLSD& sides = message["sides"]; + LLViewerObject * obj = gObjectList.findObject(object_id); + std::unordered_set side_set; + + if (result.mResults.size() > 0 ) + { + for (int i = 0; i < result.mResults.size(); ++i) + { + if (result.mResults[i]) { S32 side = sides[i].asInteger(); // flag this side to not be nulled out later side_set.insert(sides[i]); - if (!obj || !obj->setTEGLTFMaterialOverride(side, override_data)) + if (!obj || !obj->setTEGLTFMaterialOverride(side, result.mMaterialVector[i])) { // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_id, side, override_data); + gGLTFMaterialList.queueOverrideUpdate(object_id, side, result.mMaterialVector[i]); } else if (obj && obj->isAnySelected()) { LLMaterialEditor::updateLive(object_id, side); } } + else + { + // unblock material editor + if (obj && obj->isAnySelected()) + { + LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); + } + } } if (obj && side_set.size() != obj->getNumTEs()) @@ -242,24 +277,20 @@ public: } } } - else - { - LL_WARNS() << "Malformed GLTF override message data: " << message << LL_ENDL; - } - } - - if (clear_all && obj) - { // override list was empty or an error occurred, null out all overrides for this object - bool object_has_selection = obj->isAnySelected(); - for (int i = 0; i < obj->getNumTEs(); ++i) - { - obj->setTEGLTFMaterialOverride(i, nullptr); - if (object_has_selection) + else if (obj) + { // override list was empty or an error occurred, null out all overrides for this object + bool object_has_selection = obj->isAnySelected(); + for (int i = 0; i < obj->getNumTEs(); ++i) { - LLMaterialEditor::updateLive(obj->getID(), i); + obj->setTEGLTFMaterialOverride(i, nullptr); + if (object_has_selection) + { + LLMaterialEditor::updateLive(obj->getID(), i); + } } } - } + }); + return true; } }; -- cgit v1.2.3 From cdf248d9860246fd0bee84f700642709fdebbe6e Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 11 Nov 2022 22:45:42 +0200 Subject: SL-18391 Basic gltf material accounting Plan is to expand it as needed with overrides, request rate and memory --- indra/newview/llgltfmateriallist.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 206be33051..1a059ca9fd 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -37,6 +37,7 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" +#include "llviewerstats.h" #include "llcorehttputil.h" #include "llagent.h" @@ -626,6 +627,11 @@ void LLGLTFMaterialList::flushMaterials() { mLastUpdateKey.setNull(); } + + { + using namespace LLStatViewer; + sample(NUM_MATERIALS, mList.size()); + } } // static -- cgit v1.2.3 From 6c93f4232525f55b283be6881ed12db623cd5ce0 Mon Sep 17 00:00:00 2001 From: Nicky Date: Sun, 13 Nov 2022 11:18:44 +0100 Subject: Use const& as it is illegal to bind a non const reference to a temporary --- indra/newview/llgltfmateriallist.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 1a059ca9fd..19cef5dffd 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -184,8 +184,8 @@ public: if (message.has("sides") && message.has("gltf_json")) { - LLSD& sides = message.get("sides"); - LLSD& gltf_json = message.get("gltf_json"); + LLSD const& sides = message.get("sides"); + LLSD const& gltf_json = message.get("gltf_json"); if (sides.isArray() && gltf_json.isArray() && sides.size() != 0 && -- cgit v1.2.3 From 1971839517519657fc895c9cb12c47317dde6b39 Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Fri, 11 Nov 2022 10:00:37 -0800 Subject: Basic solution for SL-18458 vocache implementation for material overrides --- indra/newview/llgltfmateriallist.cpp | 48 +++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 19cef5dffd..07c6d9ff93 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -27,6 +27,7 @@ #include "llgltfmateriallist.h" +#include "llagent.h" #include "llassetstorage.h" #include "lldispatcher.h" #include "llfetchedgltfmaterial.h" @@ -37,9 +38,11 @@ #include "llviewercontrol.h" #include "llviewergenericmessage.h" #include "llviewerobjectlist.h" +#include "llviewerregion.h" #include "llviewerstats.h" #include "llcorehttputil.h" #include "llagent.h" +#include "llworld.h" #include "tinygltf/tiny_gltf.h" #include @@ -163,8 +166,14 @@ public: { LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } + LLGLTFMaterialList::writeCacheOverrides(message, llsdRaw); } - + else + { + // malformed message, nothing we can do to handle it + return false; + } + LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); @@ -676,3 +685,40 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, done_callback(success); } } + +void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string const & llsdRaw) +{ + LL_DEBUGS() << "material overrides cache" << LL_ENDL; + + // default to main region if message doesn't specify + LLViewerRegion * region = gAgent.getRegion();; + + if (message.has("region_handle")) + { + // TODO start requiring this once server sends this for all messages + std::vector const & buffer = message["region_handle"].asBinary(); + if (buffer.size() == sizeof(U64)) + { + U64 region_handle = ntohll(*reinterpret_cast(&buffer[0])); + region = LLWorld::instance().getRegionFromHandle(region_handle); + } + else + { + LL_WARNS() << "bad region_handle in material override message" << LL_ENDL; + llassert(false); + } + } + + if (region) { + region->cacheFullUpdateExtras(message, llsdRaw); + } else { + LL_WARNS() << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + } +} + +void LLGLTFMaterialList::loadCacheOverrides(std::string const & message) +{ + std::vector strings(1, message); + + handle_gltf_override_message(nullptr, "", LLUUID::null, strings); +} -- cgit v1.2.3 From 911aba0c1c3ddaae61af487bb01bf689b7dd938f Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Tue, 15 Nov 2022 12:51:28 -0800 Subject: SL-18458 VOCache cleanup region_handle message encoding. Really wish there were a native way to send S64/U64 values in llsd. --- indra/newview/llgltfmateriallist.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 07c6d9ff93..d37cf3b618 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -693,20 +693,13 @@ void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string c // default to main region if message doesn't specify LLViewerRegion * region = gAgent.getRegion();; - if (message.has("region_handle")) + if (message.has("region_handle_low") && message.has("region_handle_high")) { // TODO start requiring this once server sends this for all messages - std::vector const & buffer = message["region_handle"].asBinary(); - if (buffer.size() == sizeof(U64)) - { - U64 region_handle = ntohll(*reinterpret_cast(&buffer[0])); - region = LLWorld::instance().getRegionFromHandle(region_handle); - } - else - { - LL_WARNS() << "bad region_handle in material override message" << LL_ENDL; - llassert(false); - } + U64 region_handle_low = message["region_handle_low"].asInteger(); + U64 region_handle_high = message["region_handle_high"].asInteger(); + U64 region_handle = (region_handle_low & 0x00000000ffffffffUL) || (region_handle_high << 32); + region = LLWorld::instance().getRegionFromHandle(region_handle); } if (region) { -- cgit v1.2.3 From 7889f0b17082e12f66f81c69b63a4f20ee5e73a5 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 18 Nov 2022 15:17:05 +0200 Subject: SL-18668 Don't call makeMap from callback --- indra/newview/llgltfmateriallist.cpp | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index d37cf3b618..306e66bfb7 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -171,6 +171,16 @@ public: else { // malformed message, nothing we can do to handle it + LL_DEBUGS("GLTF") << "Empty message" << LL_ENDL; + return false; + } + + if (!message.has("sides") + || !message.has("gltf_json") + || !message.has("object_id")) + { + // malformed message, nothing we can do to handle it + LL_DEBUGS("GLTF") << "Malformed message:" << message << LL_ENDL; return false; } @@ -226,7 +236,7 @@ public: } else { - LL_WARNS() << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + LL_WARNS("GLTF") << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; } } } @@ -234,10 +244,10 @@ public: return result; }, [message](ReturnData result) // Callback to main thread - mutable { + { - LLUUID object_id = message["object_id"].asUUID(); - LLSD& sides = message["sides"]; + LLUUID object_id = message.get("object_id").asUUID(); + LLSD const& sides = message.get("sides"); LLViewerObject * obj = gObjectList.findObject(object_id); std::unordered_set side_set; @@ -449,7 +459,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp if (status != LL_ERR_NOERR) { - LL_WARNS() << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; + LL_WARNS("GLTF") << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; asset_data->mMaterial->mFetching = false; delete asset_data; } @@ -504,7 +514,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp if (!gltf.LoadASCIIFromString(&asset_data->mModelIn, &error_msg, &warn_msg, data.c_str(), data.length(), "")) { - LL_WARNS() << "Failed to decode material asset: " + LL_WARNS("GLTF") << "Failed to decode material asset: " << LL_NEWLINE << warn_msg << LL_NEWLINE @@ -519,14 +529,14 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp } else { - LL_WARNS() << "Failed to deserialize material LLSD" << LL_ENDL; + LL_WARNS("GLTF") << "Failed to deserialize material LLSD" << LL_ENDL; } } return false; }, [id, asset_data](bool result) // Callback to main thread - mutable { + { if (result) { @@ -534,7 +544,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp } else { - LL_DEBUGS() << "Failed to get material " << id << LL_ENDL; + LL_DEBUGS("GLTF") << "Failed to get material " << id << LL_ENDL; } asset_data->mMaterial->mFetching = false; delete asset_data; @@ -661,7 +671,7 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, httpOpts->setFollowRedirects(true); - LL_DEBUGS() << "Applying override via ModifyMaterialParams cap: " << overrides << LL_ENDL; + LL_DEBUGS("GLTF") << "Applying override via ModifyMaterialParams cap: " << overrides << LL_ENDL; LLSD result = httpAdapter->postAndSuspend(httpRequest, cap_url, overrides, httpOpts, httpHeaders); @@ -671,12 +681,12 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, bool success = true; if (!status) { - LL_WARNS() << "Failed to modify material." << LL_ENDL; + LL_WARNS("GLTF") << "Failed to modify material." << LL_ENDL; success = false; } else if (!result["success"].asBoolean()) { - LL_WARNS() << "Failed to modify material: " << result["message"] << LL_ENDL; + LL_WARNS("GLTF") << "Failed to modify material: " << result["message"] << LL_ENDL; success = false; } @@ -688,7 +698,7 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string const & llsdRaw) { - LL_DEBUGS() << "material overrides cache" << LL_ENDL; + LL_DEBUGS("GLTF") << "material overrides cache" << LL_ENDL; // default to main region if message doesn't specify LLViewerRegion * region = gAgent.getRegion();; @@ -705,7 +715,7 @@ void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string c if (region) { region->cacheFullUpdateExtras(message, llsdRaw); } else { - LL_WARNS() << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; } } -- cgit v1.2.3 From 32663643c77a931892a2f8e40e011c60bc726d4e Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 18 Nov 2022 19:59:50 +0200 Subject: SL-18668 Only object id is strictly required --- indra/newview/llgltfmateriallist.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 306e66bfb7..a604930715 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -175,12 +175,10 @@ public: return false; } - if (!message.has("sides") - || !message.has("gltf_json") - || !message.has("object_id")) + if (!message.has("object_id")) { // malformed message, nothing we can do to handle it - LL_DEBUGS("GLTF") << "Malformed message:" << message << LL_ENDL; + LL_DEBUGS("GLTF") << "Message without id:" << message << LL_ENDL; return false; } @@ -247,12 +245,13 @@ public: { LLUUID object_id = message.get("object_id").asUUID(); - LLSD const& sides = message.get("sides"); LLViewerObject * obj = gObjectList.findObject(object_id); - std::unordered_set side_set; if (result.mResults.size() > 0 ) { + LLSD const& sides = message.get("sides"); + std::unordered_set side_set; + for (int i = 0; i < result.mResults.size(); ++i) { if (result.mResults[i]) -- cgit v1.2.3 From 32984b56ea8fa4f4357379a40627b5e9267d7543 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 24 Nov 2022 12:16:59 +0200 Subject: SL-18701 llsd is not thread safe, parse it before using --- indra/newview/llgltfmateriallist.cpp | 161 +++++++++++++++++------------------ 1 file changed, 76 insertions(+), 85 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index a604930715..45de0b71ae 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -42,6 +42,7 @@ #include "llviewerstats.h" #include "llcorehttputil.h" #include "llagent.h" +#include "llvocache.h" #include "llworld.h" #include "tinygltf/tiny_gltf.h" @@ -159,14 +160,14 @@ public: LLSD message; sparam_t::const_iterator it = strings.begin(); - if (it != strings.end()) { + if (it != strings.end()) + { const std::string& llsdRaw = *it++; std::istringstream llsdData(llsdRaw); if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length())) { LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; } - LLGLTFMaterialList::writeCacheOverrides(message, llsdRaw); } else { @@ -175,99 +176,118 @@ public: return false; } - if (!message.has("object_id")) + LLGLTFOverrideCacheEntry object_override; + if (!object_override.fromLLSD(message)) { // malformed message, nothing we can do to handle it LL_DEBUGS("GLTF") << "Message without id:" << message << LL_ENDL; return false; } + // Cache the data + { + LL_DEBUGS("GLTF") << "material overrides cache" << LL_ENDL; + + // default to main region if message doesn't specify + LLViewerRegion * region = gAgent.getRegion();; + + if (object_override.mHasRegionHandle) + { + // TODO start requiring this once server sends this for all messages + region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle); + } + + if (region) + { + region->cacheFullUpdateGLTFOverride(object_override); + } + else + { + LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + } + } + applyData(object_override); + return true; + } + + static void applyData(const LLGLTFOverrideCacheEntry &object_override) + { + // Parse the data + LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); struct ReturnData { public: - std::vector > mMaterialVector; - std::vector mResults; + LLPointer mMaterial; + S32 mSide; + bool mSuccess; }; // fromJson() is performance heavy offload to a thread. main_queue->postTo( general_queue, - [message]() // Work done on general queue + [object_override]() // Work done on general queue { - ReturnData result; + std::vector results; - if (message.has("sides") && message.has("gltf_json")) + if (!object_override.mSides.empty()) { - LLSD const& sides = message.get("sides"); - LLSD const& gltf_json = message.get("gltf_json"); - - if (sides.isArray() && gltf_json.isArray() && - sides.size() != 0 && - sides.size() == gltf_json.size()) + results.reserve(object_override.mSides.size()); + // parse json + std::map::const_iterator iter = object_override.mSides.begin(); + std::map::const_iterator end = object_override.mSides.end(); + while (iter != end) { - // message should be interpreted thusly: - /// sides is a list of face indices - // gltf_json is a list of corresponding json - // any side not represented in "sides" has no override - result.mResults.resize(sides.size()); - result.mMaterialVector.resize(sides.size()); - - // parse json - for (int i = 0; i < sides.size(); ++i) - { - LLPointer override_data = new LLGLTFMaterial(); - - std::string gltf_json_str = gltf_json[i].asString(); + LLPointer override_data = new LLGLTFMaterial(); + std::string warn_msg, error_msg; - std::string warn_msg, error_msg; + bool success = override_data->fromJSON(iter->second, warn_msg, error_msg); - bool success = override_data->fromJSON(gltf_json_str, warn_msg, error_msg); + ReturnData result; + result.mSuccess = success; + result.mSide = iter->first; - result.mResults[i] = success; - - if (success) - { - result.mMaterialVector[i] = override_data; - } - else - { - LL_WARNS("GLTF") << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; - } + if (success) + { + result.mMaterial = override_data; } + else + { + LL_WARNS("GLTF") << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; + } + + results.push_back(result); + iter++; } } - return result; + return results; }, - [message](ReturnData result) // Callback to main thread + [object_override](std::vector results) // Callback to main thread { - LLUUID object_id = message.get("object_id").asUUID(); - LLViewerObject * obj = gObjectList.findObject(object_id); + LLViewerObject * obj = gObjectList.findObject(object_override.mObjectId); - if (result.mResults.size() > 0 ) + if (results.size() > 0 ) { - LLSD const& sides = message.get("sides"); std::unordered_set side_set; - for (int i = 0; i < result.mResults.size(); ++i) + for (int i = 0; i < results.size(); ++i) { - if (result.mResults[i]) + if (results[i].mSuccess) { - S32 side = sides[i].asInteger(); // flag this side to not be nulled out later - side_set.insert(sides[i]); + side_set.insert(results[i].mSide); - if (!obj || !obj->setTEGLTFMaterialOverride(side, result.mMaterialVector[i])) + if (!obj || !obj->setTEGLTFMaterialOverride(results[i].mSide, results[i].mMaterial)) { // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_id, side, result.mMaterialVector[i]); + gGLTFMaterialList.queueOverrideUpdate(object_override.mObjectId, results[i].mSide, results[i].mMaterial); } else if (obj && obj->isAnySelected()) { - LLMaterialEditor::updateLive(object_id, side); + LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); } } else @@ -275,7 +295,7 @@ public: // unblock material editor if (obj && obj->isAnySelected()) { - LLMaterialEditor::updateLive(object_id, sides[i].asInteger()); + LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); } } } @@ -290,7 +310,7 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (object_has_selection) { - LLMaterialEditor::updateLive(object_id, i); + LLMaterialEditor::updateLive(object_override.mObjectId, i); } } } @@ -309,8 +329,6 @@ public: } } }); - - return true; } }; @@ -439,8 +457,6 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) sUpdates = LLSD::emptyArray(); } - - } class AssetLoadUserData @@ -695,32 +711,7 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, } } -void LLGLTFMaterialList::writeCacheOverrides(LLSD const & message, std::string const & llsdRaw) +void LLGLTFMaterialList::loadCacheOverrides(const LLGLTFOverrideCacheEntry& override) { - LL_DEBUGS("GLTF") << "material overrides cache" << LL_ENDL; - - // default to main region if message doesn't specify - LLViewerRegion * region = gAgent.getRegion();; - - if (message.has("region_handle_low") && message.has("region_handle_high")) - { - // TODO start requiring this once server sends this for all messages - U64 region_handle_low = message["region_handle_low"].asInteger(); - U64 region_handle_high = message["region_handle_high"].asInteger(); - U64 region_handle = (region_handle_low & 0x00000000ffffffffUL) || (region_handle_high << 32); - region = LLWorld::instance().getRegionFromHandle(region_handle); - } - - if (region) { - region->cacheFullUpdateExtras(message, llsdRaw); - } else { - LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; - } -} - -void LLGLTFMaterialList::loadCacheOverrides(std::string const & message) -{ - std::vector strings(1, message); - - handle_gltf_override_message(nullptr, "", LLUUID::null, strings); + LLGLTFMaterialOverrideDispatchHandler::applyData(override); } -- cgit v1.2.3 From a989eba0808b2e5fda5494ff3b109784aa79984e Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 21 Nov 2022 16:09:07 -0800 Subject: SL-18732: Fix flickering of control values when changing GLTF texture transforms in build floater --- indra/newview/llgltfmateriallist.cpp | 40 +++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 45de0b71ae..cff2d22f18 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -147,6 +147,11 @@ public: LLGLTFMaterialOverrideDispatchHandler() = default; ~LLGLTFMaterialOverrideDispatchHandler() override = default; + void addCallback(void(*callback)(const LLUUID& object_id, S32 side)) + { + mCallbacks.push_back(callback); + } + bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override { LL_PROFILE_ZONE_SCOPED; @@ -210,7 +215,7 @@ public: return true; } - static void applyData(const LLGLTFOverrideCacheEntry &object_override) + void applyData(const LLGLTFOverrideCacheEntry &object_override) { // Parse the data @@ -225,6 +230,8 @@ public: bool mSuccess; }; + std::vector callbacks = mCallbacks; + // fromJson() is performance heavy offload to a thread. main_queue->postTo( general_queue, @@ -264,7 +271,7 @@ public: } return results; }, - [object_override](std::vector results) // Callback to main thread + [object_override, callbacks](std::vector results) // Callback to main thread { LLViewerObject * obj = gObjectList.findObject(object_override.mObjectId); @@ -288,6 +295,10 @@ public: else if (obj && obj->isAnySelected()) { LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); + for (auto& override_update_callback : callbacks) + { + override_update_callback(object_override.mObjectId, results[i].mSide); + } } } else @@ -296,6 +307,10 @@ public: if (obj && obj->isAnySelected()) { LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); + for (auto& override_update_callback : callbacks) + { + override_update_callback(object_override.mObjectId, results[i].mSide); + } } } } @@ -311,6 +326,10 @@ public: if (object_has_selection) { LLMaterialEditor::updateLive(object_override.mObjectId, i); + for (auto& override_update_callback : callbacks) + { + override_update_callback(object_override.mObjectId, i); + } } } } @@ -325,11 +344,17 @@ public: if (object_has_selection) { LLMaterialEditor::updateLive(obj->getID(), i); + for (auto& override_update_callback : callbacks) + { + override_update_callback(obj->getID(), i); + } } } } }); } + + std::vector mCallbacks; }; namespace @@ -371,6 +396,10 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) if (object_has_selection) { LLMaterialEditor::updateLive(id, i); + for (auto& override_update_callback : handle_gltf_override_message.mCallbacks) + { + override_update_callback(id, i); + } } } } @@ -459,6 +488,11 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) } } +void LLGLTFMaterialList::addUpdateCallback(void(*update_callback)(const LLUUID& object_id, S32 side)) +{ + handle_gltf_override_message.addCallback(update_callback); +} + class AssetLoadUserData { public: @@ -713,5 +747,5 @@ void LLGLTFMaterialList::modifyMaterialCoro(std::string cap_url, LLSD overrides, void LLGLTFMaterialList::loadCacheOverrides(const LLGLTFOverrideCacheEntry& override) { - LLGLTFMaterialOverrideDispatchHandler::applyData(override); + handle_gltf_override_message.applyData(override); } -- cgit v1.2.3 From 361571cdb330dea18ad5a3575d7b06c69371e11b Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 29 Nov 2022 13:51:23 -0800 Subject: SL-18732: Use override update callback for LLMaterialEditor::updateLive as well --- indra/newview/llgltfmateriallist.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index cff2d22f18..8142762dfe 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -32,7 +32,6 @@ #include "lldispatcher.h" #include "llfetchedgltfmaterial.h" #include "llfilesystem.h" -#include "llmaterialeditor.h" #include "llsdserialize.h" #include "lltinygltfhelper.h" #include "llviewercontrol.h" @@ -294,7 +293,6 @@ public: } else if (obj && obj->isAnySelected()) { - LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); for (auto& override_update_callback : callbacks) { override_update_callback(object_override.mObjectId, results[i].mSide); @@ -306,7 +304,6 @@ public: // unblock material editor if (obj && obj->isAnySelected()) { - LLMaterialEditor::updateLive(object_override.mObjectId, results[i].mSide); for (auto& override_update_callback : callbacks) { override_update_callback(object_override.mObjectId, results[i].mSide); @@ -325,7 +322,6 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (object_has_selection) { - LLMaterialEditor::updateLive(object_override.mObjectId, i); for (auto& override_update_callback : callbacks) { override_update_callback(object_override.mObjectId, i); @@ -343,7 +339,6 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (object_has_selection) { - LLMaterialEditor::updateLive(obj->getID(), i); for (auto& override_update_callback : callbacks) { override_update_callback(obj->getID(), i); @@ -395,7 +390,6 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) obj->setTEGLTFMaterialOverride(i, overrides[i]); if (object_has_selection) { - LLMaterialEditor::updateLive(id, i); for (auto& override_update_callback : handle_gltf_override_message.mCallbacks) { override_update_callback(id, i); -- cgit v1.2.3 From cf86c23dfe1fd732cd939b7fd48fdc7b88bdce1c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 29 Nov 2022 14:23:18 -0800 Subject: SL-18732: Pass material list callbacks by reference --- indra/newview/llgltfmateriallist.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 8142762dfe..048085fb71 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -229,8 +229,6 @@ public: bool mSuccess; }; - std::vector callbacks = mCallbacks; - // fromJson() is performance heavy offload to a thread. main_queue->postTo( general_queue, @@ -270,7 +268,7 @@ public: } return results; }, - [object_override, callbacks](std::vector results) // Callback to main thread + [object_override, this](std::vector results) // Callback to main thread { LLViewerObject * obj = gObjectList.findObject(object_override.mObjectId); @@ -293,7 +291,7 @@ public: } else if (obj && obj->isAnySelected()) { - for (auto& override_update_callback : callbacks) + for (auto& override_update_callback : mCallbacks) { override_update_callback(object_override.mObjectId, results[i].mSide); } @@ -304,7 +302,7 @@ public: // unblock material editor if (obj && obj->isAnySelected()) { - for (auto& override_update_callback : callbacks) + for (auto& override_update_callback : mCallbacks) { override_update_callback(object_override.mObjectId, results[i].mSide); } @@ -322,7 +320,7 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (object_has_selection) { - for (auto& override_update_callback : callbacks) + for (auto& override_update_callback : mCallbacks) { override_update_callback(object_override.mObjectId, i); } @@ -339,7 +337,7 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (object_has_selection) { - for (auto& override_update_callback : callbacks) + for (auto& override_update_callback : mCallbacks) { override_update_callback(obj->getID(), i); } -- cgit v1.2.3 From bfcb07270ed7036c87a4ece7fa1f5416123fff85 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 29 Nov 2022 15:20:44 -0800 Subject: SL-18732: Review feedback --- indra/newview/llgltfmateriallist.cpp | 56 ++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 048085fb71..d04a674e91 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -148,7 +148,7 @@ public: void addCallback(void(*callback)(const LLUUID& object_id, S32 side)) { - mCallbacks.push_back(callback); + mSelectionCallbacks.push_back(callback); } bool operator()(const LLDispatcher* dispatcher, const std::string& key, const LLUUID& invoice, const sparam_t& strings) override @@ -214,6 +214,14 @@ public: return true; } + void doSelectionCallbacks(const LLUUID& object_id, S32 side) + { + for (auto& callback : mSelectionCallbacks) + { + callback(object_id, side); + } + } + void applyData(const LLGLTFOverrideCacheEntry &object_override) { // Parse the data @@ -289,41 +297,31 @@ public: // object not ready to receive override data, queue for later gGLTFMaterialList.queueOverrideUpdate(object_override.mObjectId, results[i].mSide, results[i].mMaterial); } - else if (obj && obj->isAnySelected()) + else if (obj && obj->getTE(i) && obj->getTE(i)->isSelected()) { - for (auto& override_update_callback : mCallbacks) - { - override_update_callback(object_override.mObjectId, results[i].mSide); - } + doSelectionCallbacks(object_override.mObjectId, results[i].mSide); } } else { // unblock material editor - if (obj && obj->isAnySelected()) + if (obj && obj->getTE(i) && obj->getTE(i)->isSelected()) { - for (auto& override_update_callback : mCallbacks) - { - override_update_callback(object_override.mObjectId, results[i].mSide); - } + doSelectionCallbacks(object_override.mObjectId, results[i].mSide); } } } if (obj && side_set.size() != obj->getNumTEs()) { // object exists and at least one texture entry needs to have its override data nulled out - bool object_has_selection = obj->isAnySelected(); for (int i = 0; i < obj->getNumTEs(); ++i) { if (side_set.find(i) == side_set.end()) { obj->setTEGLTFMaterialOverride(i, nullptr); - if (object_has_selection) + if (obj->getTE(i) && obj->getTE(i)->isSelected()) { - for (auto& override_update_callback : mCallbacks) - { - override_update_callback(object_override.mObjectId, i); - } + doSelectionCallbacks(object_override.mObjectId, i); } } } @@ -331,23 +329,21 @@ public: } else if (obj) { // override list was empty or an error occurred, null out all overrides for this object - bool object_has_selection = obj->isAnySelected(); for (int i = 0; i < obj->getNumTEs(); ++i) { obj->setTEGLTFMaterialOverride(i, nullptr); - if (object_has_selection) + if (obj->getTE(i) && obj->getTE(i)->isSelected()) { - for (auto& override_update_callback : mCallbacks) - { - override_update_callback(obj->getID(), i); - } + doSelectionCallbacks(obj->getID(), i); } } } }); } - std::vector mCallbacks; +private: + + std::vector mSelectionCallbacks; }; namespace @@ -375,23 +371,19 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) if (iter != mQueuedOverrides.end()) { - bool object_has_selection = obj->isAnySelected(); override_list_t& overrides = iter->second; for (int i = 0; i < overrides.size(); ++i) { if (overrides[i].notNull()) { - if (!obj->getTE(i)->getGLTFMaterial()) + if (!obj->getTE(i) || !obj->getTE(i)->getGLTFMaterial()) { // object doesn't have its base GLTF material yet, don't apply override (yet) return; } obj->setTEGLTFMaterialOverride(i, overrides[i]); - if (object_has_selection) + if (obj->getTE(i)->isSelected()) { - for (auto& override_update_callback : handle_gltf_override_message.mCallbacks) - { - override_update_callback(id, i); - } + handle_gltf_override_message.doSelectionCallbacks(id, i); } } } @@ -480,7 +472,7 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) } } -void LLGLTFMaterialList::addUpdateCallback(void(*update_callback)(const LLUUID& object_id, S32 side)) +void LLGLTFMaterialList::addSelectionUpdateCallback(void(*update_callback)(const LLUUID& object_id, S32 side)) { handle_gltf_override_message.addCallback(update_callback); } -- cgit v1.2.3 From afa6692efa9c744d6043438ba755c6119273b899 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 10 Jan 2023 23:01:27 +0200 Subject: SL-18942 [PBR] LLPanelFace was missing 'transform' updates for some of the faces --- indra/newview/llgltfmateriallist.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index d04a674e91..4aea0fcbcc 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -297,7 +297,7 @@ public: // object not ready to receive override data, queue for later gGLTFMaterialList.queueOverrideUpdate(object_override.mObjectId, results[i].mSide, results[i].mMaterial); } - else if (obj && obj->getTE(i) && obj->getTE(i)->isSelected()) + else if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) { doSelectionCallbacks(object_override.mObjectId, results[i].mSide); } @@ -305,7 +305,7 @@ public: else { // unblock material editor - if (obj && obj->getTE(i) && obj->getTE(i)->isSelected()) + if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) { doSelectionCallbacks(object_override.mObjectId, results[i].mSide); } -- cgit v1.2.3 From 693925ef23ef41e3927a9654a7f423d0e24ce19a Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 13 Dec 2022 10:41:21 -0800 Subject: SL-18820: Fix applying material clearing transform overrides. Loosen some asserts to allow non-default transform overrides. --- indra/newview/llgltfmateriallist.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index d04a674e91..9539ffc700 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -404,9 +404,19 @@ void LLGLTFMaterialList::queueModify(const LLUUID& id, S32 side, const LLGLTFMat } } -void LLGLTFMaterialList::queueApply(const LLUUID& object_id, S32 side, const LLUUID& asset_id) +void LLGLTFMaterialList::queueApply(const LLViewerObject* obj, S32 side, const LLUUID& asset_id) { - sApplyQueue.push_back({ object_id, side, asset_id}); + const LLGLTFMaterial* material_override = obj->getTE(side)->getGLTFMaterialOverride(); + if (material_override) + { + LLGLTFMaterial* cleared_override = new LLGLTFMaterial(*material_override); + cleared_override->setBaseMaterial(); + sApplyQueue.push_back({ obj->getID(), side, asset_id, cleared_override }); + } + else + { + sApplyQueue.push_back({ obj->getID(), side, asset_id, nullptr }); + } } void LLGLTFMaterialList::queueUpdate(const LLSD& data) @@ -436,6 +446,11 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) { data[i]["gltf_json"] = e.override_data.asJSON(); } + else + { + // Clear all overrides + data[i]["gltf_json"] = ""; + } llassert(is_valid_update(data[i])); ++i; @@ -447,7 +462,15 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) data[i]["object_id"] = e.object_id; data[i]["side"] = e.side; data[i]["asset_id"] = e.asset_id; - data[i]["gltf_json"] = ""; // null out any existing overrides when applying a material asset + if (e.override_data) + { + data[i]["gltf_json"] = e.override_data->asJSON(); + } + else + { + // Clear all overrides + data[i]["gltf_json"] = ""; + } llassert(is_valid_update(data[i])); ++i; -- cgit v1.2.3 From a3f43b4b73cc8fbd48a0574ebd74bbe660f8af50 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 23 Jan 2023 19:17:46 +0200 Subject: SL-19014 Sanitize the override data sent for faces without GLTF materials --- indra/newview/llgltfmateriallist.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 9399342a61..4cf1562042 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -392,15 +392,18 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) } } -void LLGLTFMaterialList::queueModify(const LLUUID& id, S32 side, const LLGLTFMaterial* mat) +void LLGLTFMaterialList::queueModify(const LLViewerObject* obj, S32 side, const LLGLTFMaterial* mat) { - if (mat == nullptr) + if (obj && obj->getRenderMaterialID(side).notNull()) { - sModifyQueue.push_back({ id, side, LLGLTFMaterial(), false }); - } - else - { - sModifyQueue.push_back({ id, side, *mat, true}); + if (mat == nullptr) + { + sModifyQueue.push_back({ obj->getID(), side, LLGLTFMaterial(), false }); + } + else + { + sModifyQueue.push_back({ obj->getID(), side, *mat, true }); + } } } @@ -437,8 +440,14 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) S32 i = data.size(); - for (auto& e : sModifyQueue) + for (ModifyMaterialData& e : sModifyQueue) { +#ifdef SHOW_ASSERT + // validate object has a material id + LLViewerObject* obj = gObjectList.findObject(e.object_id); + llassert(obj && obj->getRenderMaterialID(e.side).notNull()); +#endif + data[i]["object_id"] = e.object_id; data[i]["side"] = e.side; -- cgit v1.2.3 From 2aaa15fef15243e6b38f46426d8ebb355ccfb807 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 24 Jan 2023 17:48:18 -0800 Subject: SL-19012: Fix new material IDs sometimes not applying when set via LSL --- indra/newview/llgltfmateriallist.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 4cf1562042..bc094ac838 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -525,7 +525,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp if (status != LL_ERR_NOERR) { LL_WARNS("GLTF") << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL; - asset_data->mMaterial->mFetching = false; + asset_data->mMaterial->materialComplete(); delete asset_data; } else @@ -611,13 +611,15 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp { LL_DEBUGS("GLTF") << "Failed to get material " << id << LL_ENDL; } - asset_data->mMaterial->mFetching = false; + + asset_data->mMaterial->materialComplete(); + delete asset_data; }); } } -LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) +LLFetchedGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) { LL_PROFILE_ZONE_SCOPED; uuid_mat_map_t::iterator iter = mList.find(id); @@ -629,7 +631,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) if (!mat->mFetching) { - mat->mFetching = true; + mat->materialBegin(); AssetLoadUserData *user_data = new AssetLoadUserData(); user_data->mMaterial = mat; -- cgit v1.2.3 From d6841c07983a46ff805ed23a7318efbf9cca3b24 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 9 Feb 2023 15:04:46 -0800 Subject: SL-19080: Update GLTF Material asset upload to v1.1, with stricter GLTF compliance and removal of unsupported features --- indra/newview/llgltfmateriallist.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index bc094ac838..4051521ad4 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -564,9 +564,9 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp if (LLSDSerialize::deserialize(asset, str, buffer.size())) { - if (asset.has("version") && asset["version"] == "1.0") + if (asset.has("version") && LLGLTFMaterial::isAcceptedVersion(asset["version"].asString())) { - if (asset.has("type") && asset["type"].asString() == "GLTF 2.0") + if (asset.has("type") && asset["type"].asString() == LLGLTFMaterial::ASSET_TYPE) { if (asset.has("data") && asset["data"].isString()) { -- cgit v1.2.3 From 6e6bac6b4025e01ee636b8490edbe09db2497722 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Tue, 21 Mar 2023 13:40:00 -0700 Subject: Phase 2 of fix for SL-18458 material overrides not being cached properly --- indra/newview/llgltfmateriallist.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 4051521ad4..d0c1c73f0e 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -157,8 +157,8 @@ public: // receive override data from simulator via LargeGenericMessage // message should have: // object_id - UUID of LLViewerObject - // side - S32 index of texture entry - // gltf_json - String of GLTF json for override data + // sides - array of S32 indices of texture entries + // gltf_json - array of corresponding Strings of GLTF json for override data LLSD message; @@ -380,11 +380,22 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) { // object doesn't have its base GLTF material yet, don't apply override (yet) return; } - obj->setTEGLTFMaterialOverride(i, overrides[i]); + + S32 status = obj->setTEGLTFMaterialOverride(i, overrides[i]); + if (status == TEM_CHANGE_NONE) + { + // can't apply this yet, since failure to change the material override + // probably means the base material is still being fetched. leave in + // the queue for later + return; + } + if (obj->getTE(i)->isSelected()) { handle_gltf_override_message.doSelectionCallbacks(id, i); } + // success! + overrides[i] = nullptr; } } -- cgit v1.2.3 From 81bccc05e296b80163bf28aea537e9ded2a0927e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 23 Mar 2023 13:33:21 -0500 Subject: SL-18458 Fix for overrides not applying if material is not loaded on rebuild. --- indra/newview/llgltfmateriallist.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index d0c1c73f0e..678ec7e46b 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -376,8 +376,14 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) { if (overrides[i].notNull()) { - if (!obj->getTE(i) || !obj->getTE(i)->getGLTFMaterial()) - { // object doesn't have its base GLTF material yet, don't apply override (yet) + if (!obj->getTE(i)) + { // object is incomplete + return; + } + + if (!obj->getTE(i)->getGLTFMaterial()) + { + // doesn't have its base GLTF material yet, don't apply override(yet) return; } @@ -387,6 +393,7 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) // can't apply this yet, since failure to change the material override // probably means the base material is still being fetched. leave in // the queue for later + //obj->setDebugText("early out 3"); return; } -- cgit v1.2.3 From cf3a0c77f1855aa1a33ff39f86e846e7fb9031d1 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Thu, 23 Mar 2023 16:51:30 -0700 Subject: Fix for SL-18458 overrides not applying when cache load happened before LLViewerObject::updateTEMaterialTextures call --- indra/newview/llgltfmateriallist.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 678ec7e46b..9c78e48cab 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -366,6 +366,8 @@ void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFM void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) { LL_PROFILE_ZONE_SCOPED; + + llassert(obj); const LLUUID& id = obj->getID(); auto iter = mQueuedOverrides.find(id); -- cgit v1.2.3 From 1b6cd23abdc9e5208076d55cce9f06bc2a0713a1 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Wed, 29 Mar 2023 17:05:40 -0700 Subject: CMake and tests fixups after merge with main for DRTVWR-559 --- indra/newview/llgltfmateriallist.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 9c78e48cab..57a67f52f6 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -554,8 +554,6 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); - typedef std::pair return_data_t; - main_queue->postTo( general_queue, [id, asset_type, asset_data]() // Work done on general queue -- cgit v1.2.3 From 7c831d115b55b96129806353a51a01dcf2bcebba Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 3 Apr 2023 17:22:40 -0500 Subject: SL-18458 Make LLVOCache the one source of truth on most recently received overrides. (#147) --- indra/newview/llgltfmateriallist.cpp | 45 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 57a67f52f6..08ce43434f 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -192,14 +192,7 @@ public: { LL_DEBUGS("GLTF") << "material overrides cache" << LL_ENDL; - // default to main region if message doesn't specify - LLViewerRegion * region = gAgent.getRegion();; - - if (object_override.mHasRegionHandle) - { - // TODO start requiring this once server sends this for all messages - region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle); - } + LLViewerRegion * region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle); if (region) { @@ -248,8 +241,8 @@ public: { results.reserve(object_override.mSides.size()); // parse json - std::map::const_iterator iter = object_override.mSides.begin(); - std::map::const_iterator end = object_override.mSides.end(); + std::unordered_map::const_iterator iter = object_override.mSides.begin(); + std::unordered_map::const_iterator end = object_override.mSides.end(); while (iter != end) { LLPointer override_data = new LLGLTFMaterial(); @@ -278,7 +271,6 @@ public: }, [object_override, this](std::vector results) // Callback to main thread { - LLViewerObject * obj = gObjectList.findObject(object_override.mObjectId); if (results.size() > 0 ) @@ -292,23 +284,16 @@ public: // flag this side to not be nulled out later side_set.insert(results[i].mSide); - if (!obj || !obj->setTEGLTFMaterialOverride(results[i].mSide, results[i].mMaterial)) + if (obj) { - // object not ready to receive override data, queue for later - gGLTFMaterialList.queueOverrideUpdate(object_override.mObjectId, results[i].mSide, results[i].mMaterial); - } - else if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) - { - doSelectionCallbacks(object_override.mObjectId, results[i].mSide); + obj->setTEGLTFMaterialOverride(results[i].mSide, results[i].mMaterial); } } - else + + // unblock material editor + if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) { - // unblock material editor - if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) - { - doSelectionCallbacks(object_override.mObjectId, results[i].mSide); - } + doSelectionCallbacks(object_override.mObjectId, results[i].mSide); } } @@ -353,6 +338,7 @@ namespace void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFMaterial* override_data) { +#if 0 override_list_t& overrides = mQueuedOverrides[id]; if (overrides.size() < side + 1) @@ -361,6 +347,7 @@ void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFM } overrides[side] = override_data; +#endif } void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) @@ -368,6 +355,8 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) LL_PROFILE_ZONE_SCOPED; llassert(obj); + +#if 0 const LLUUID& id = obj->getID(); auto iter = mQueuedOverrides.find(id); @@ -410,6 +399,14 @@ void LLGLTFMaterialList::applyQueuedOverrides(LLViewerObject* obj) mQueuedOverrides.erase(iter); } +#else + // the override cache is the authoritarian source of the most recent override data + LLViewerRegion* regionp = obj->getRegion(); + if (regionp) + { + regionp->applyCacheMiscExtras(obj); + } +#endif } void LLGLTFMaterialList::queueModify(const LLViewerObject* obj, S32 side, const LLGLTFMaterial* mat) -- cgit v1.2.3 From 45fdba8fd96ed714cbc0120b0a10a4c5b63ea706 Mon Sep 17 00:00:00 2001 From: Brad Linden <46733234+brad-linden@users.noreply.github.com> Date: Wed, 19 Apr 2023 09:41:07 -0700 Subject: Implement SL-19605 handling of batched material overrides in LargeGenericMessage (#177) --- indra/newview/llgltfmateriallist.cpp | 56 ++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 08ce43434f..151d7fa969 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -162,49 +162,43 @@ public: LLSD message; - - sparam_t::const_iterator it = strings.begin(); - if (it != strings.end()) + bool success = true; + for(const std::string& llsdRaw : strings) { - const std::string& llsdRaw = *it++; std::istringstream llsdData(llsdRaw); if (!LLSDSerialize::deserialize(message, llsdData, llsdRaw.length())) { LL_WARNS() << "LLGLTFMaterialOverrideDispatchHandler: Attempted to read parameter data into LLSD but failed:" << llsdRaw << LL_ENDL; + success = false; + continue; } - } - else - { - // malformed message, nothing we can do to handle it - LL_DEBUGS("GLTF") << "Empty message" << LL_ENDL; - return false; - } - - LLGLTFOverrideCacheEntry object_override; - if (!object_override.fromLLSD(message)) - { - // malformed message, nothing we can do to handle it - LL_DEBUGS("GLTF") << "Message without id:" << message << LL_ENDL; - return false; - } - - // Cache the data - { - LL_DEBUGS("GLTF") << "material overrides cache" << LL_ENDL; - - LLViewerRegion * region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle); - if (region) + LLGLTFOverrideCacheEntry object_override; + if (!object_override.fromLLSD(message)) { - region->cacheFullUpdateGLTFOverride(object_override); + // malformed message, nothing we can do to handle it + LL_DEBUGS("GLTF") << "Message without id:" << message << LL_ENDL; + success = false; + continue; } - else + + // Cache the data { - LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + LLViewerRegion * region = LLWorld::instance().getRegionFromHandle(object_override.mRegionHandle); + + if (region) + { + region->cacheFullUpdateGLTFOverride(object_override); + } + else + { + LL_WARNS("GLTF") << "could not access region for material overrides message cache, region_handle: " << LL_ENDL; + } } + applyData(object_override); } - applyData(object_override); - return true; + + return success; } void doSelectionCallbacks(const LLUUID& object_id, S32 side) -- cgit v1.2.3 From 3513f67d2c5628eac2ce9aa632a8491bb215a9e8 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Mon, 17 Apr 2023 10:24:23 -0700 Subject: Attempt at fixing thread safety possibly related to SL-19648 --- indra/newview/llgltfmateriallist.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 151d7fa969..7d677626ce 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -219,7 +219,7 @@ public: struct ReturnData { public: - LLPointer mMaterial; + LLGLTFMaterial mMaterial; S32 mSide; bool mSuccess; }; @@ -239,20 +239,16 @@ public: std::unordered_map::const_iterator end = object_override.mSides.end(); while (iter != end) { - LLPointer override_data = new LLGLTFMaterial(); std::string warn_msg, error_msg; - bool success = override_data->fromJSON(iter->second, warn_msg, error_msg); - ReturnData result; + + bool success = result.mMaterial.fromJSON(iter->second, warn_msg, error_msg); + result.mSuccess = success; result.mSide = iter->first; - if (success) - { - result.mMaterial = override_data; - } - else + if (!success) { LL_WARNS("GLTF") << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; } @@ -271,23 +267,27 @@ public: { std::unordered_set side_set; - for (int i = 0; i < results.size(); ++i) + for (auto const & result : results) { - if (results[i].mSuccess) + S32 side = result.mSide; + if (result.mSuccess) { + // copy to heap here because LLTextureEntry is going to take ownership with an LLPointer + LLGLTFMaterial * material = new LLGLTFMaterial(result.mMaterial); + // flag this side to not be nulled out later - side_set.insert(results[i].mSide); + side_set.insert(side); if (obj) { - obj->setTEGLTFMaterialOverride(results[i].mSide, results[i].mMaterial); + obj->setTEGLTFMaterialOverride(side, material); } } // unblock material editor - if (obj && obj->getTE(results[i].mSide) && obj->getTE(results[i].mSide)->isSelected()) + if (obj && obj->getTE(side) && obj->getTE(side)->isSelected()) { - doSelectionCallbacks(object_override.mObjectId, results[i].mSide); + doSelectionCallbacks(object_override.mObjectId, side); } } -- cgit v1.2.3 From 6a812fa1ba9170ba34706d303913cc5aa5f187ac Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Wed, 3 May 2023 13:23:05 -0700 Subject: Improved fix for SL-19675 crash. How about just don't refer to data when you don't need it --- indra/newview/llgltfmateriallist.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 7d677626ce..1e49ea2eba 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -227,16 +227,16 @@ public: // fromJson() is performance heavy offload to a thread. main_queue->postTo( general_queue, - [object_override]() // Work done on general queue + [sides=object_override.mSides]() // Work done on general queue { std::vector results; - if (!object_override.mSides.empty()) + if (!sides.empty()) { - results.reserve(object_override.mSides.size()); + results.reserve(sides.size()); // parse json - std::unordered_map::const_iterator iter = object_override.mSides.begin(); - std::unordered_map::const_iterator end = object_override.mSides.end(); + std::unordered_map::const_iterator iter = sides.begin(); + std::unordered_map::const_iterator end = sides.end(); while (iter != end) { std::string warn_msg, error_msg; @@ -259,9 +259,9 @@ public: } return results; }, - [object_override, this](std::vector results) // Callback to main thread + [object_id=object_override.mObjectId, this](std::vector results) // Callback to main thread { - LLViewerObject * obj = gObjectList.findObject(object_override.mObjectId); + LLViewerObject * obj = gObjectList.findObject(object_id); if (results.size() > 0 ) { @@ -287,7 +287,7 @@ public: // unblock material editor if (obj && obj->getTE(side) && obj->getTE(side)->isSelected()) { - doSelectionCallbacks(object_override.mObjectId, side); + doSelectionCallbacks(object_id, side); } } @@ -300,7 +300,7 @@ public: obj->setTEGLTFMaterialOverride(i, nullptr); if (obj->getTE(i) && obj->getTE(i)->isSelected()) { - doSelectionCallbacks(object_override.mObjectId, i); + doSelectionCallbacks(object_id, i); } } } -- cgit v1.2.3 From 5465594a34ec65c1f4eeb9181be190e47e6527ad Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Wed, 3 May 2023 13:28:29 -0700 Subject: Cleanup with SL-19675 fix. lifted empty check outside the workqueue post and cleaned up indentation --- indra/newview/llgltfmateriallist.cpp | 98 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 1e49ea2eba..ed16a1cf7a 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -224,15 +224,15 @@ public: bool mSuccess; }; - // fromJson() is performance heavy offload to a thread. - main_queue->postTo( - general_queue, - [sides=object_override.mSides]() // Work done on general queue + if (!object_override.mSides.empty()) { - std::vector results; - - if (!sides.empty()) + // fromJson() is performance heavy offload to a thread. + main_queue->postTo( + general_queue, + [sides=object_override.mSides]() // Work done on general queue { + std::vector results; + results.reserve(sides.size()); // parse json std::unordered_map::const_iterator iter = sides.begin(); @@ -256,68 +256,68 @@ public: results.push_back(result); iter++; } - } - return results; - }, + return results; + }, [object_id=object_override.mObjectId, this](std::vector results) // Callback to main thread { - LLViewerObject * obj = gObjectList.findObject(object_id); - - if (results.size() > 0 ) - { - std::unordered_set side_set; + LLViewerObject * obj = gObjectList.findObject(object_id); - for (auto const & result : results) + if (results.size() > 0 ) { - S32 side = result.mSide; - if (result.mSuccess) + std::unordered_set side_set; + + for (auto const & result : results) { - // copy to heap here because LLTextureEntry is going to take ownership with an LLPointer - LLGLTFMaterial * material = new LLGLTFMaterial(result.mMaterial); + S32 side = result.mSide; + if (result.mSuccess) + { + // copy to heap here because LLTextureEntry is going to take ownership with an LLPointer + LLGLTFMaterial * material = new LLGLTFMaterial(result.mMaterial); - // flag this side to not be nulled out later - side_set.insert(side); + // flag this side to not be nulled out later + side_set.insert(side); - if (obj) + if (obj) + { + obj->setTEGLTFMaterialOverride(side, material); + } + } + + // unblock material editor + if (obj && obj->getTE(side) && obj->getTE(side)->isSelected()) { - obj->setTEGLTFMaterialOverride(side, material); + doSelectionCallbacks(object_id, side); } } - - // unblock material editor - if (obj && obj->getTE(side) && obj->getTE(side)->isSelected()) - { - doSelectionCallbacks(object_id, side); - } - } - if (obj && side_set.size() != obj->getNumTEs()) - { // object exists and at least one texture entry needs to have its override data nulled out - for (int i = 0; i < obj->getNumTEs(); ++i) - { - if (side_set.find(i) == side_set.end()) + if (obj && side_set.size() != obj->getNumTEs()) + { // object exists and at least one texture entry needs to have its override data nulled out + for (int i = 0; i < obj->getNumTEs(); ++i) { - obj->setTEGLTFMaterialOverride(i, nullptr); - if (obj->getTE(i) && obj->getTE(i)->isSelected()) + if (side_set.find(i) == side_set.end()) { - doSelectionCallbacks(object_id, i); + obj->setTEGLTFMaterialOverride(i, nullptr); + if (obj->getTE(i) && obj->getTE(i)->isSelected()) + { + doSelectionCallbacks(object_id, i); + } } } } } - } - else if (obj) - { // override list was empty or an error occurred, null out all overrides for this object - for (int i = 0; i < obj->getNumTEs(); ++i) - { - obj->setTEGLTFMaterialOverride(i, nullptr); - if (obj->getTE(i) && obj->getTE(i)->isSelected()) + else if (obj) + { // override list was empty or an error occurred, null out all overrides for this object + for (int i = 0; i < obj->getNumTEs(); ++i) { - doSelectionCallbacks(obj->getID(), i); + obj->setTEGLTFMaterialOverride(i, nullptr); + if (obj->getTE(i) && obj->getTE(i)->isSelected()) + { + doSelectionCallbacks(obj->getID(), i); + } } } - } - }); + }); + } } private: -- cgit v1.2.3 From f8f119e4a8b6d3c1f106f5e290d1da187fd9aa17 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 4 May 2023 22:46:24 +0300 Subject: SL-18932 Canceling material selection only reverts override --- indra/newview/llgltfmateriallist.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index ed16a1cf7a..99a052f719 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -433,6 +433,19 @@ void LLGLTFMaterialList::queueApply(const LLViewerObject* obj, S32 side, const L } } +void LLGLTFMaterialList::queueApply(const LLViewerObject* obj, S32 side, const LLUUID& asset_id, const LLGLTFMaterial* material_override) +{ + if (asset_id.isNull() || material_override == nullptr) + { + queueApply(obj, side, asset_id); + } + else + { + LLGLTFMaterial* material = new LLGLTFMaterial(*material_override); + sApplyQueue.push_back({ obj->getID(), side, asset_id, material }); + } +} + void LLGLTFMaterialList::queueUpdate(const LLSD& data) { llassert(is_valid_update(data)); @@ -477,7 +490,7 @@ void LLGLTFMaterialList::flushUpdates(void(*done_callback)(bool)) } sModifyQueue.clear(); - for (auto& e : sApplyQueue) + for (ApplyMaterialAssetData& e : sApplyQueue) { data[i]["object_id"] = e.object_id; data[i]["side"] = e.side; -- cgit v1.2.3 From 455bbcf742691b709353aa3c3e35a76d0ff38ee4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 29 Aug 2023 16:42:55 -0500 Subject: SL-20229 Add GenericStreamingMessage and use it to receive GLTF material overrides --- indra/newview/llgltfmateriallist.cpp | 75 +++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 13 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 99a052f719..a204315a2a 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -160,9 +160,9 @@ public: // sides - array of S32 indices of texture entries // gltf_json - array of corresponding Strings of GLTF json for override data - LLSD message; bool success = true; +#if 0 //deprecated for(const std::string& llsdRaw : strings) { std::istringstream llsdData(llsdRaw); @@ -198,6 +198,7 @@ public: applyData(object_override); } +#endif return success; } @@ -213,6 +214,7 @@ public: { // Parse the data +#if 0 // DEPRECATED LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop"); LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General"); @@ -235,24 +237,17 @@ public: results.reserve(sides.size()); // parse json - std::unordered_map::const_iterator iter = sides.begin(); - std::unordered_map::const_iterator end = sides.end(); + std::unordered_map::const_iterator iter = sides.begin(); + std::unordered_map::const_iterator end = sides.end(); while (iter != end) { - std::string warn_msg, error_msg; - ReturnData result; - bool success = result.mMaterial.fromJSON(iter->second, warn_msg, error_msg); - - result.mSuccess = success; + result.mMaterial.applyOverrideLLSD(iter->second); + + result.mSuccess = true; result.mSide = iter->first; - if (!success) - { - LL_WARNS("GLTF") << "failed to parse GLTF override data. errors: " << error_msg << " | warnings: " << warn_msg << LL_ENDL; - } - results.push_back(result); iter++; } @@ -318,6 +313,7 @@ public: } }); } +#endif } private: @@ -330,6 +326,59 @@ namespace LLGLTFMaterialOverrideDispatchHandler handle_gltf_override_message; } +void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::string& data_in) +{ + std::istringstream str(data_in); + + LLSD data; + + LLSDSerialize::fromNotation(data, str, data_in.length()); + + const LLHost& host = msg->getSender(); + + LLViewerRegion* region = LLWorld::instance().getRegion(host); + + if (region) + { + U32 local_id = data.get("id").asInteger(); + LLUUID id; + gObjectList.getUUIDFromLocal(id, local_id, host.getAddress(), host.getPort()); + LLViewerObject* obj = gObjectList.findObject(id); + + if (obj) + { + const LLSD& tes = data["te"]; + const LLSD& od = data["od"]; + + if (tes.isArray()) + { + LLGLTFOverrideCacheEntry cache; + cache.mLocalId = local_id; + cache.mObjectId = id; + cache.mRegionHandle = region->getHandle(); + + for (int i = 0; i < tes.size(); ++i) + { + S32 te = tes[i].asInteger(); + LLGLTFMaterial* mat = new LLGLTFMaterial(); // setTEGLTFMaterialOverride will take ownership + mat->applyOverrideLLSD(od[i]); + obj->setTEGLTFMaterialOverride(te, mat); + + cache.mSides[te] = od[i]; + cache.mGLTFMaterial[te] = mat; + + if (obj->getTE(te) && obj->getTE(te)->isSelected()) + { + handle_gltf_override_message.doSelectionCallbacks(id, te); + } + } + + region->cacheFullUpdateGLTFOverride(cache); + } + } + } +} + void LLGLTFMaterialList::queueOverrideUpdate(const LLUUID& id, S32 side, LLGLTFMaterial* override_data) { #if 0 -- cgit v1.2.3 From db480d11fe69e54fb0387c6624657673b2f414e9 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 18 Sep 2023 14:16:15 -0500 Subject: SL-20229 Add blip for GLTF messages to "Show Updates to Objects" --- indra/newview/llgltfmateriallist.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index a204315a2a..655311f53d 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -347,6 +347,12 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s if (obj) { + if (gShowObjectUpdates) + { // display a cyan blip for override updates when "Show Updates to Objects" enabled + LLColor4 color(0.f, 1.f, 1.f, 1.f); + gPipeline.addDebugBlip(obj->getPositionAgent(), color); + } + const LLSD& tes = data["te"]; const LLSD& od = data["od"]; -- cgit v1.2.3 From 83fb74720f27b8a203bc7a143931ecc5b4770c01 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 18 Sep 2023 15:55:23 -0500 Subject: SL-20229 Cache GLTF updates that are received before the object they're applied to is loaded. --- indra/newview/llgltfmateriallist.cpp | 53 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 655311f53d..0bdfcf05e7 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -337,6 +337,7 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s const LLHost& host = msg->getSender(); LLViewerRegion* region = LLWorld::instance().getRegion(host); + llassert(region); if (region) { @@ -345,43 +346,47 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s gObjectList.getUUIDFromLocal(id, local_id, host.getAddress(), host.getPort()); LLViewerObject* obj = gObjectList.findObject(id); - if (obj) - { - if (gShowObjectUpdates) - { // display a cyan blip for override updates when "Show Updates to Objects" enabled - LLColor4 color(0.f, 1.f, 1.f, 1.f); - gPipeline.addDebugBlip(obj->getPositionAgent(), color); - } + // NOTE: obj may be null if the viewer hasn't heard about the object yet, cache update in any case + + if (obj && gShowObjectUpdates) + { // display a cyan blip for override updates when "Show Updates to Objects" enabled + LLColor4 color(0.f, 1.f, 1.f, 1.f); + gPipeline.addDebugBlip(obj->getPositionAgent(), color); + } - const LLSD& tes = data["te"]; - const LLSD& od = data["od"]; + const LLSD& tes = data["te"]; + const LLSD& od = data["od"]; - if (tes.isArray()) + if (tes.isArray()) + { + LLGLTFOverrideCacheEntry cache; + cache.mLocalId = local_id; + cache.mObjectId = id; + cache.mRegionHandle = region->getHandle(); + + for (int i = 0; i < tes.size(); ++i) { - LLGLTFOverrideCacheEntry cache; - cache.mLocalId = local_id; - cache.mObjectId = id; - cache.mRegionHandle = region->getHandle(); + LLGLTFMaterial* mat = new LLGLTFMaterial(); // setTEGLTFMaterialOverride and cache will take ownership + mat->applyOverrideLLSD(od[i]); - for (int i = 0; i < tes.size(); ++i) - { - S32 te = tes[i].asInteger(); - LLGLTFMaterial* mat = new LLGLTFMaterial(); // setTEGLTFMaterialOverride will take ownership - mat->applyOverrideLLSD(od[i]); - obj->setTEGLTFMaterialOverride(te, mat); + S32 te = tes[i].asInteger(); - cache.mSides[te] = od[i]; - cache.mGLTFMaterial[te] = mat; + cache.mSides[te] = od[i]; + cache.mGLTFMaterial[te] = mat; + if (obj) + { + obj->setTEGLTFMaterialOverride(te, mat); if (obj->getTE(te) && obj->getTE(te)->isSelected()) { handle_gltf_override_message.doSelectionCallbacks(id, te); } } - - region->cacheFullUpdateGLTFOverride(cache); } + + region->cacheFullUpdateGLTFOverride(cache); } + } } -- cgit v1.2.3 From 360ffff2885bff2f816c099dc414dc126cb7e258 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 21 Sep 2023 14:54:22 -0500 Subject: SL-20321 Interpret missing TEs in override messages as indication overrides should be nulled out if present. --- indra/newview/llgltfmateriallist.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 0bdfcf05e7..a92e699c42 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -357,6 +357,9 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s const LLSD& tes = data["te"]; const LLSD& od = data["od"]; + constexpr U32 MAX_TES = 45; + bool has_te[MAX_TES] = { false }; + if (tes.isArray()) { LLGLTFOverrideCacheEntry cache; @@ -364,13 +367,15 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s cache.mObjectId = id; cache.mRegionHandle = region->getHandle(); - for (int i = 0; i < tes.size(); ++i) + U32 count = llmin(tes.size(), MAX_TES); + for (U32 i = 0; i < count; ++i) { LLGLTFMaterial* mat = new LLGLTFMaterial(); // setTEGLTFMaterialOverride and cache will take ownership mat->applyOverrideLLSD(od[i]); S32 te = tes[i].asInteger(); + has_te[te] = true; cache.mSides[te] = od[i]; cache.mGLTFMaterial[te] = mat; @@ -384,6 +389,20 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s } } + if (obj) + { // null out overrides on TEs that shouldn't have them + U32 count = llmin(obj->getNumTEs(), MAX_TES); + for (U32 i = 0; i < count; ++i) + { + LLTextureEntry* te = obj->getTE(i); + if (te && te->getGLTFMaterialOverride()) + { + obj->setTEGLTFMaterialOverride(i, nullptr); + handle_gltf_override_message.doSelectionCallbacks(id, i); + } + } + } + region->cacheFullUpdateGLTFOverride(cache); } -- cgit v1.2.3 From 3da26ee8df6cc7e57ba3acbb91437ec97e151002 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 22 Sep 2023 15:31:49 -0500 Subject: SL-20321 Fix for missing "has_te" check (thanks Henri) --- indra/newview/llgltfmateriallist.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/llgltfmateriallist.cpp') diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index a92e699c42..8919229c78 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -360,8 +360,8 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s constexpr U32 MAX_TES = 45; bool has_te[MAX_TES] = { false }; - if (tes.isArray()) - { + if (tes.isArray()) // NOTE: if no "te" array exists, this is a malformed message (null out all overrides will come in as an empty te array) + { LLGLTFOverrideCacheEntry cache; cache.mLocalId = local_id; cache.mObjectId = id; @@ -395,7 +395,7 @@ void LLGLTFMaterialList::applyOverrideMessage(LLMessageSystem* msg, const std::s for (U32 i = 0; i < count; ++i) { LLTextureEntry* te = obj->getTE(i); - if (te && te->getGLTFMaterialOverride()) + if (!has_te[i] && te && te->getGLTFMaterialOverride()) { obj->setTEGLTFMaterialOverride(i, nullptr); handle_gltf_override_message.doSelectionCallbacks(id, i); -- cgit v1.2.3