summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorcosmic-linden <111533034+cosmic-linden@users.noreply.github.com>2023-11-01 12:42:17 -0700
committerGitHub <noreply@github.com>2023-11-01 12:42:17 -0700
commit911dcb40fdf90d4f1e647860d257f7c13914ee49 (patch)
tree620f1d30526cf65baf5aef6a01c0251b553a764a /indra
parentda71aa168e7a82ef0821d032c6509febcfc6185b (diff)
parent326e7a2b4ec668d1b163f81c2a1c7dab87aa45df (diff)
Merge pull request #486 from secondlife/SL-20397
SL-20397: Fix material set from script not updating when the GLTF material has non-default texture transforms
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llviewerobject.cpp46
-rw-r--r--indra/newview/llviewerobject.h2
2 files changed, 43 insertions, 5 deletions
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index 028fea29c2..3b5b986725 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -7266,14 +7266,17 @@ void LLViewerObject::rebuildMaterial()
gPipeline.markTextured(mDrawable);
}
-void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool update_server)
+void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool update_server, bool local_origin)
{
// implementation is delicate
// if update is bound for server, should always null out GLTFRenderMaterial and clear GLTFMaterialOverride even if ids haven't changed
// (the case where ids haven't changed indicates the user has reapplied the original material, in which case overrides should be dropped)
// otherwise, should only null out the render material where ids or overrides have changed
- // (the case where ids have changed but overrides are still present is from unsynchronized updates from the simulator)
+ // (the case where ids have changed but overrides are still present is from unsynchronized updates from the simulator, or synchronized
+ // updates with solely transform overrides)
+
+ llassert(!update_server || local_origin);
S32 start_idx = 0;
S32 end_idx = getNumTEs();
@@ -7305,7 +7308,12 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
{
LLTextureEntry* tep = getTE(te);
- bool material_changed = !param_block || id != param_block->getMaterial(te);
+ // If local_origin=false (i.e. it's from the server), we know the
+ // material has updated or been created, because extra params are
+ // checked for equality on unpacking. In that case, checking the
+ // material ID for inequality won't work, because the material ID has
+ // already been set.
+ bool material_changed = !local_origin || !param_block || id != param_block->getMaterial(te);
if (update_server)
{
@@ -7327,6 +7335,34 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
{
tep->setGLTFMaterial(new_material, !update_server);
}
+
+ if (material_changed && new_material)
+ {
+ // Sometimes, the material may change out from underneath the overrides.
+ // This is usually due to the server sending a new material ID, but
+ // the overrides have not changed due to being only texture
+ // transforms. Re-apply the overrides to the render material here,
+ // if present.
+ const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride();
+ if (override_material)
+ {
+ new_material->onMaterialComplete([obj_id = getID(), te]()
+ {
+ LLViewerObject* obj = gObjectList.findObject(obj_id);
+ if (!obj) { return; }
+ LLTextureEntry* tep = obj->getTE(te);
+ if (!tep) { return; }
+ const LLGLTFMaterial* new_material = tep->getGLTFMaterial();
+ if (!new_material) { return; }
+ const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride();
+ if (!override_material) { return; }
+ LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial();
+ *render_material = *new_material;
+ render_material->applyOverride(*override_material);
+ tep->setGLTFRenderMaterial(render_material);
+ });
+ }
+ }
}
// signal to render pipe that render batches must be rebuilt for this object
@@ -7386,7 +7422,9 @@ void LLViewerObject::setRenderMaterialIDs(const LLRenderMaterialParams* material
for (S32 te = 0; te < getNumTEs(); ++te)
{
const LLUUID& id = material_params ? material_params->getMaterial(te) : LLUUID::null;
- setRenderMaterialID(te, id, false);
+ // We know material_params has updated or been created, because
+ // extra params are checked for equality on unpacking.
+ setRenderMaterialID(te, id, false, false);
}
}
}
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index ec7bf36f71..80da7b2f73 100644
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -190,7 +190,7 @@ public:
// te - TextureEntry index to set, or -1 for all TEs
// id - asset id of material asset
// update_server - if true, will send updates to server and clear most overrides
- void setRenderMaterialID(S32 te, const LLUUID& id, bool update_server = true);
+ void setRenderMaterialID(S32 te, const LLUUID& id, bool update_server = true, bool local_origin = true);
void setRenderMaterialIDs(const LLUUID& id);
virtual BOOL isHUDAttachment() const { return FALSE; }