From b35cfb489a78110b705f7afe878d258523727fa6 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Fri, 6 Apr 2018 20:29:32 +0100
Subject: [PATCH] MAINT-8239 - avatar remembers which meshes it knows overrides
 for, making some updates more efficient. addAttachmentOverrides() called in
 rebuildGeom()

---
 indra/newview/llvoavatar.cpp | 22 ++++++++++++++++++++--
 indra/newview/llvoavatar.h   |  4 +++-
 indra/newview/llvovolume.cpp |  7 ++++++-
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index edb7856de1..a31d48dc4f 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -5794,6 +5794,8 @@ void LLVOAvatar::clearAttachmentOverrides()
 {
     LLScopedContextString str("clearAttachmentOverrides " + getFullname());
 
+    mActiveOverrideMeshes.clear();
+    
     for (S32 i=0; i<LL_CHARACTER_MAX_ANIMATED_JOINTS; i++)
     {
         LLJoint *pJoint = getJoint(i);
@@ -5920,10 +5922,24 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo)
 			const F32 pelvisZOffset = pSkinData->mPelvisOffset;
 			const LLUUID& mesh_id = pSkinData->mMeshID;
 
-            LL_DEBUGS("AnimatedObjects") << "adding attachment overrides for " << mesh_id << " to root object " << root_object->getID() << LL_ENDL;
+            bool mesh_overrides_loaded = (mActiveOverrideMeshes.find(mesh_id) != mActiveOverrideMeshes.end());
+            if (mesh_overrides_loaded)
+            {
+                LL_DEBUGS("AnimatedObjects") << "skipping add attachment overrides for " << mesh_id 
+                                             << " to root object " << root_object->getID()
+                                             << ", already loaded"
+                                             << LL_ENDL;
+            }
+            else
+            {
+                LL_DEBUGS("AnimatedObjects") << "adding attachment overrides for " << mesh_id 
+                                             << " to root object " << root_object->getID() << LL_ENDL;
+            }
 			bool fullRig = (jointCnt>=JOINT_COUNT_REQUIRED_FOR_FULLRIG) ? true : false;								
-			if ( fullRig )
+			if ( fullRig && !mesh_overrides_loaded )
 			{								
+                mActiveOverrideMeshes.insert(mesh_id);
+                
 				for ( int i=0; i<jointCnt; ++i )
 				{
 					std::string lookingForJoint = pSkinData->mJointNames[i].c_str();
@@ -6127,6 +6143,8 @@ void LLVOAvatar::removeAttachmentOverridesForObject(LLViewerObject *vo)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::removeAttachmentOverridesForObject(const LLUUID& mesh_id)
 {	
+    mActiveOverrideMeshes.erase(mesh_id);
+
 	//Subsequent joints are relative to pelvis
 	avatar_joint_list_t::iterator iter = mSkeleton.begin();
 	avatar_joint_list_t::iterator end  = mSkeleton.end();
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index d7b67de2ad..92ea40affd 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -214,7 +214,9 @@ public:
     void                    showAttachmentOverrides(bool verbose = false) const;
     void                    getAttachmentOverrideNames(std::set<std::string>& pos_names, 
                                                        std::set<std::string>& scale_names) const;
-	
+
+    std::set<LLUUID>		mActiveOverrideMeshes;
+    
 	/*virtual*/ const LLUUID&	getID() const;
 	/*virtual*/ void			addDebugText(const std::string& text);
 	/*virtual*/ F32				getTimeDilation();
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 094b0b77dd..9f8c8aba74 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -3530,7 +3530,7 @@ void LLVOVolume::afterReparent()
         // notifyMeshLoaded() not being called reliably enough.
         
         // was: getControlAvatar()->addAttachmentOverridesForObject(this);
-        getControlAvatar()->rebuildAttachmentOverrides();
+        //getControlAvatar()->rebuildAttachmentOverrides();
         getControlAvatar()->updateAnimations();
     }
     else
@@ -5152,6 +5152,11 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
 
 			drawablep->clearState(LLDrawable::HAS_ALPHA);
 
+            if (vobj->isRiggedMesh() && vobj->getAvatar())
+            {
+                vobj->getAvatar()->addAttachmentOverridesForObject(vobj);
+            }
+            
             // Standard rigged mesh attachments: 
 			bool rigged = !vobj->isAnimatedObject() && vobj->isRiggedMesh() && vobj->isAttachment();
             // Animated objects. Have to check for isRiggedMesh() to
-- 
GitLab