diff options
author | Brad Kittenbrink <brad@lindenlab.com> | 2022-10-19 09:18:24 -0700 |
---|---|---|
committer | Brad Kittenbrink <brad@lindenlab.com> | 2022-10-19 09:18:24 -0700 |
commit | d0c2c862efe2ce684b48092465cc753b3ab64da9 (patch) | |
tree | fada5a3d37dc69eaa07630cbe395375835114ec6 | |
parent | f575c139300a6c53fa13dd0d7cbfbaa739e2b4b0 (diff) |
SL-18105 viewer side for handling Material Override LargeGenericMessage
LLGLTFMaterialList now decodes gltf json overrides from the server
and stores them in LLTextureEntry::mGLTFMaterialOverrides
-rw-r--r-- | indra/llprimitive/lltextureentry.h | 8 | ||||
-rw-r--r-- | indra/newview/llgltfmateriallist.cpp | 55 |
2 files changed, 50 insertions, 13 deletions
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index 1549b2ce87..24875f0d21 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -200,6 +200,10 @@ public: // Media flags enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 }; + // GLTF override + LLGLTFMaterial* getGLTFMaterialOverride() { return mGLTFMaterialOverrides; } + void setGLTFMaterialOverride(LLGLTFMaterial* mat) { mGLTFMaterialOverrides = mat; } + public: F32 mScaleS; // S, T offset F32 mScaleT; // S, T offset @@ -228,6 +232,10 @@ protected: LLMaterialPtr mMaterial; LLPointer<LLGLTFMaterial> mGLTFMaterial; // if present, ignore mMaterial + // GLTF material parameter overrides -- the viewer will use this data to override material parameters + // set by the asset + LLPointer<LLGLTFMaterial> mGLTFMaterialOverrides; + // Note the media data is not sent via the same message structure as the rest of the TE LLMediaEntry* mMediaEntry; // The media data for the face 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 <strstream> +#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<LLGLTFMaterial> 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; } }; |