diff options
Diffstat (limited to 'indra/newview/llgltfmateriallist.cpp')
-rw-r--r-- | indra/newview/llgltfmateriallist.cpp | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/indra/newview/llgltfmateriallist.cpp b/indra/newview/llgltfmateriallist.cpp index 5cbf853179..a433644e0e 100644 --- a/indra/newview/llgltfmateriallist.cpp +++ b/indra/newview/llgltfmateriallist.cpp @@ -28,13 +28,47 @@ #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 <strstream> +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 + { + 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 + std::string warn_msg, error_msg; + LLGLTFMaterial override_data; + override_data.fromJSON(s, warn_msg, error_msg); +#endif + } + + return true; + } + }; + LLGLTFOverrideDispatchHandler handle_gltf_override_message; +} + LLGLTFMaterialList gGLTFMaterialList; LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id) @@ -83,18 +117,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; - - tinygltf::Model model_in; + std::string warn_msg, error_msg; - 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; @@ -128,3 +153,8 @@ void LLGLTFMaterialList::removeMaterial(const LLUUID& id) mList.erase(id); } +// static +void LLGLTFMaterialList::registerCallbacks() +{ + gGenericDispatcher.addHandler("GLTF", &handle_gltf_override_message); +} |