From 57a7f63dcce6eb20a05dbc42bfdc9ac51072cb7e Mon Sep 17 00:00:00 2001
From: Howard Stearns <howard.stearns@gmail.com>
Date: Fri, 4 Feb 2022 09:55:05 -0800
Subject: [PATCH] SL-98 - Render a "ground plane" in the model upload preview,
 so users can see any added offset

---
 indra/newview/llfloatermodelpreview.cpp |  1 +
 indra/newview/llfloatermodelpreview.h   |  1 +
 indra/newview/llmodelpreview.cpp        |  6 ++++-
 indra/newview/llvoavatar.cpp            | 32 ++++++++++++++++++++++++-
 indra/newview/llvoavatar.h              |  1 +
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 64b24d54c3d..165adf46440 100644
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -270,6 +270,7 @@ BOOL LLFloaterModelPreview::postBuild()
     LLPanel *panel = mTabContainer->getPanelByName("rigging_panel");
     mAvatarTabIndex = mTabContainer->getIndexForPanel(panel);
     panel->getChild<LLScrollListCtrl>("joints_list")->setCommitCallback(boost::bind(&LLFloaterModelPreview::onJointListSelection, this));
+    mPhysicsTabIndex = mTabContainer->getIndexForPanel(mTabContainer->getPanelByName("physics_panel"));
 
 	if (LLConvexDecomposition::getInstance() != NULL)
 	{
diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h
index 8a01b0c3077..bb2b00351f7 100644
--- a/indra/newview/llfloatermodelpreview.h
+++ b/indra/newview/llfloatermodelpreview.h
@@ -231,6 +231,7 @@ class LLFloaterModelPreview : public LLFloaterModelUploadBase
 	LLTabContainer* mTabContainer;
 
 	S32			mAvatarTabIndex; // just to avoid any issues in case of xml changes
+	S32			mPhysicsTabIndex;
 	std::string	mSelectedJointName;
 
 	joint_override_data_map_t mJointOverrides[LLModel::NUM_LODS];
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index a9e80ab5da1..88ef88d2976 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -3404,7 +3404,10 @@ BOOL LLModelPreview::render()
                 {
                     gDebugProgram.bind();
                 }
-                getPreviewAvatar()->renderCollisionVolumes();
+                if (fmp->mTabContainer->getCurrentPanelIndex() == fmp->mPhysicsTabIndex)
+                {  // Physics collision volumes obscure a lot, so only show them when on the physics tab.
+                    getPreviewAvatar()->renderCollisionVolumes();
+                }
                 if (fmp->mTabContainer->getCurrentPanelIndex() == fmp->mAvatarTabIndex)
                 {
                     getPreviewAvatar()->renderBones(fmp->mSelectedJointName);
@@ -3413,6 +3416,7 @@ BOOL LLModelPreview::render()
                 {
                     getPreviewAvatar()->renderBones();
                 }
+                getPreviewAvatar()->renderGroundPlane(mPelvisZOffset);
                 if (shader)
                 {
                     shader->bind();
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 5d994058c2e..812a5c4fe6f 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @File llvoavatar.cpp
  * @brief Implementation of LLVOAvatar class which is a derivation of LLViewerObject
  *
@@ -1673,6 +1673,36 @@ void LLVOAvatar::renderBones(const std::string &selected_joint)
 	}
 }
 
+void LLVOAvatar::renderGroundPlane(float z_offset)
+{   // Not necesarilly general - beware - but it seems to meet the needs of LLModelPreview::render
+	LLVector3 root_pos = mRoot->getPosition();
+	const LLVector4a* ext = mDrawable->getSpatialExtents();
+	auto min = ext[0], max = ext[1];
+	auto center = (max - min) * 0.5f;
+	F32 ground = root_pos[2] - center[2] - z_offset;
+
+	LLVector3 vA{min[0], min[1], ground};
+	LLVector3 vB{max[0], min[1], ground};
+	LLVector3 vC{max[0], max[1], ground};
+	LLVector3 vD{min[0], max[1], ground};
+
+	gGL.diffuseColor3f( 1.0f, 0.0f, 1.0f );
+
+	gGL.begin(LLRender::LINES);
+	gGL.vertex3fv(vA.mV);
+	gGL.vertex3fv(vB.mV);
+
+	gGL.vertex3fv(vB.mV);
+	gGL.vertex3fv(vC.mV);
+
+	gGL.vertex3fv(vC.mV);
+	gGL.vertex3fv(vD.mV);
+
+	gGL.vertex3fv(vD.mV);
+	gGL.vertex3fv(vA.mV);
+
+	gGL.end();
+}
 
 void LLVOAvatar::renderJoints()
 {
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 74ef589ca47..b4d27baf207 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -486,6 +486,7 @@ class LLVOAvatar :
 	void 		renderCollisionVolumes();
 	void		renderBones(const std::string &selected_joint = std::string());
 	void		renderJoints();
+	void		renderGroundPlane(float z_offset = 0.0f);
 	static void	deleteCachedImages(bool clearAll=true);
 	static void	destroyGL();
 	static void	restoreGL();
-- 
GitLab