summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llprimitive/lltextureentry.h8
-rw-r--r--indra/newview/llgltfmateriallist.cpp55
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;
}
};