From ec471497f5dba41e74afc6864ab0f7100659e1d9 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Fri, 29 Apr 2016 11:25:17 -0400
Subject: [PATCH] SL-375, SL-378 - rudimentary logging info to list joint
 offsets during mesh import. dae_tool.py work to enable joint offset tweaking.

---
 indra/llcharacter/lljoint.cpp           | 16 +++++
 indra/newview/llfloatermodelpreview.cpp | 10 ++-
 indra/newview/llvoavatar.cpp            | 85 +++++++++++++++++--------
 indra/newview/llvoavatar.h              |  3 +-
 indra/newview/llvovolume.cpp            |  4 ++
 scripts/content_tools/dae_tool.py       |  4 +-
 6 files changed, 91 insertions(+), 31 deletions(-)

diff --git a/indra/llcharacter/lljoint.cpp b/indra/llcharacter/lljoint.cpp
index 8365ab8eb17..c4eda0b432b 100755
--- a/indra/llcharacter/lljoint.cpp
+++ b/indra/llcharacter/lljoint.cpp
@@ -382,6 +382,13 @@ void showJointPosOverrides( const LLJoint& joint, const std::string& note, const
         LL_DEBUGS("Avatar") << av_info << " joint " << joint.getName() << " " << note << " " << os.str() << LL_ENDL;
 }
 
+bool above_joint_pos_threshold(const LLVector3& diff)
+{
+	//return !diff.isNull();
+	const F32 max_joint_pos_offset = 0.0001f; // 0.1 mm
+	return diff.lengthSquared() > max_joint_pos_offset * max_joint_pos_offset;
+}
+
 //--------------------------------------------------------------------
 // addAttachmentPosOverride()
 //--------------------------------------------------------------------
@@ -391,6 +398,15 @@ void LLJoint::addAttachmentPosOverride( const LLVector3& pos, const LLUUID& mesh
 	{
 		return;
 	}
+    if (!above_joint_pos_threshold(pos-getDefaultPosition()))
+    {
+        if (do_debug_joint(getName()))
+        {
+            LL_DEBUGS("Avatar") << "Attachment pos override ignored for " << getName()
+                                << ", pos " << pos << " is same as default pos" << LL_ENDL;
+        }
+		return;
+    }
 	if (!m_attachmentOverrides.count())
 	{
 		if (do_debug_joint(getName()))
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index cda704f47b6..ec4f8a42e05 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -489,10 +489,18 @@ void LLFloaterModelPreview::onClickCalculateBtn()
 	bool upload_skinweights = childGetValue("upload_skin").asBoolean();
 	bool upload_joint_positions = childGetValue("upload_joints").asBoolean();
 
+    if (upload_joint_positions)
+    {
+        // Diagnostic message showing list of joints for which joint offsets are defined.
+        // FIXME - given time, would be much better to put this in the UI, in updateStatusMessages().
+		mModelPreview->getPreviewAvatar()->showAttachmentPosOverrides();
+    }
+
 	mUploadModelUrl.clear();
 
 	gMeshRepo.uploadModel(mModelPreview->mUploadData, mModelPreview->mPreviewScale,
-			childGetValue("upload_textures").asBoolean(), upload_skinweights, upload_joint_positions, mUploadModelUrl, false,
+                          childGetValue("upload_textures").asBoolean(), upload_skinweights, upload_joint_positions,
+                          mUploadModelUrl, false,
 						  getWholeModelFeeObserverHandle());
 
 	toggleCalculateButton(false);
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 5d77b1238a4..679ea88a44c 100755
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -5315,13 +5315,6 @@ void LLVOAvatar::clearAttachmentPosOverrides()
 	}
 }
 
-bool above_joint_pos_threshold(const LLVector3& diff)
-{
-    //return !diff.isNull();
-    const F32 max_joint_pos_offset = 0.0001f; // 0.1 mm
-    return diff.lengthSquared() > max_joint_pos_offset * max_joint_pos_offset;
-}
-
 //-----------------------------------------------------------------------------
 // addAttachmentPosOverridesForObject
 //-----------------------------------------------------------------------------
@@ -5382,22 +5375,14 @@ void LLVOAvatar::addAttachmentPosOverridesForObject(LLViewerObject *vo)
 					{   									
 						pJoint->setId( currentId );
 						const LLVector3& jointPos = pSkinData->mAlternateBindMatrix[i].getTranslation();									
-                        if (!above_joint_pos_threshold(jointPos-pJoint->getDefaultPosition()))
-                        {
-                            LL_DEBUGS("Avatar") << "Attachment pos override ignored for " << pJoint->getName()
-                                                << ", pos " << jointPos << " is same as default pos" << LL_ENDL;
-                        }
-                        else
-                        {
-                            //Set the joint position
-                            pJoint->addAttachmentPosOverride( jointPos, mesh_id, avString() );
+                        //Set the joint position
+                        pJoint->addAttachmentPosOverride( jointPos, mesh_id, avString() );
                             
-                            //If joint is a pelvis then handle old/new pelvis to foot values
-                            if ( lookingForJoint == "mPelvis" )
-                            {	
-                                pelvisGotSet = true;											
-                            }										
-                        }
+                        //If joint is a pelvis then handle old/new pelvis to foot values
+                        if ( lookingForJoint == "mPelvis" )
+                        {	
+                            pelvisGotSet = true;											
+                        }										
 					}										
 				}																
 				if (pelvisZOffset != 0.0F)
@@ -5414,22 +5399,68 @@ void LLVOAvatar::addAttachmentPosOverridesForObject(LLViewerObject *vo)
 	{
 		postPelvisSetRecalc();
 	}		
+}
 
-    if (isSelf())
-    {
-        showAttachmentPosOverrides();
+//-----------------------------------------------------------------------------
+// getAttachmentOverrideNames
+//-----------------------------------------------------------------------------
+void LLVOAvatar::getAttachmentOverrideNames(std::set<std::string>& names) const
+{
+    LLVector3 pos;
+    LLUUID mesh_id;
+
+    // Bones
+	for (avatar_joint_list_t::const_iterator iter = mSkeleton.begin();
+         iter != mSkeleton.end(); ++iter)
+	{
+		const LLJoint* pJoint = (*iter);
+		if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
+		{
+            names.insert(pJoint->getName());
+		}
+	}
+
+    // Attachment points
+	for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin();
+		 iter != mAttachmentPoints.end();
+		 ++iter)
+	{
+		const LLViewerJointAttachment *attachment_pt = (*iter).second;
+        if (attachment_pt && attachment_pt->hasAttachmentPosOverride(pos,mesh_id))
+        {
+            names.insert(attachment_pt->getName());
+        }
     }
+
 }
 
 //-----------------------------------------------------------------------------
 // showAttachmentPosOverrides
 //-----------------------------------------------------------------------------
-void LLVOAvatar::showAttachmentPosOverrides() const
+void LLVOAvatar::showAttachmentPosOverrides(bool verbose) const
 {
+    std::set<std::string> joint_names;
+    getAttachmentOverrideNames(joint_names);
+    if (joint_names.size())
+    {
+        std::stringstream ss;
+        std::copy(joint_names.begin(), joint_names.end(), std::ostream_iterator<std::string>(ss, ","));
+        LL_INFOS() << getFullname() << " attachment positions defined for joints: " << ss.str() << "\n" << LL_ENDL;
+    }
+    else
+    {
+        LL_INFOS() << getFullname() << " no attachment positions defined for any joints" << "\n" << LL_ENDL;
+    }
+
+    if (!verbose)
+    {
+        return;
+    }
+
     LLVector3 pos;
     LLUUID mesh_id;
     S32 count = 0;
-    
+
     // Bones
 	for (avatar_joint_list_t::const_iterator iter = mSkeleton.begin();
          iter != mSkeleton.end(); ++iter)
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 48c0d0e54b2..c6bc2fd58fc 100755
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -206,7 +206,8 @@ class LLVOAvatar :
     bool					jointIsRiggedTo(const std::string& joint_name);
     bool					jointIsRiggedTo(const std::string& joint_name, const LLViewerObject *vo);
 	void					clearAttachmentPosOverrides();
-    void                    showAttachmentPosOverrides() const;
+    void                    showAttachmentPosOverrides(bool verbose = false) const;
+    void                    getAttachmentOverrideNames(std::set<std::string>& names) const;
 	
 	/*virtual*/ const LLUUID&	getID() const;
 	/*virtual*/ void			addDebugText(const std::string& text);
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index c2550afcacd..9d8ef05cbc1 100755
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -4777,6 +4777,10 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
             if (rigged && pAvatarVO)
             {
                 pAvatarVO->addAttachmentPosOverridesForObject(vobj);
+				if (pAvatarVO->isSelf())
+				{
+					//pAvatarVO->showAttachmentPosOverrides();
+				}
             }
 
 			//for each face
diff --git a/scripts/content_tools/dae_tool.py b/scripts/content_tools/dae_tool.py
index 08d78b1df93..8ac6c7582fc 100644
--- a/scripts/content_tools/dae_tool.py
+++ b/scripts/content_tools/dae_tool.py
@@ -47,8 +47,8 @@ def mesh_lock_offsets(tree, joints):
             continue
         if joint_node.get("type") != "JOINT":
             continue
-        if joint_node.get("name") in joints:
-            for matrix_node in joint_node.iter():
+        if joint_node.get("name") in joints or "bone" in joints:
+            for matrix_node in list(joint_node):
                 if "matrix" in matrix_node.tag:
                     floats = [float(x) for x in matrix_node.text.split()]
                     if len(floats) == 16:
-- 
GitLab