From 53a6a46a8fc50d819a462f6f0836b3b017f45574 Mon Sep 17 00:00:00 2001
From: Cinder <cinder@sdf.org>
Date: Mon, 27 Jul 2015 18:31:34 -0600
Subject: [PATCH] Basic OpenSim build constraints

---
 indra/llmath/llvolume.cpp               |  6 ++---
 indra/llmath/xform.h                    | 12 ++++++---
 indra/llprimitive/llprimitive.cpp       |  6 ++++-
 indra/llprimitive/llprimitive.h         |  6 ++++-
 indra/newview/llfloatermodelpreview.cpp |  3 ++-
 indra/newview/llmanipscale.cpp          | 22 +++++++++------
 indra/newview/llmaniptranslate.cpp      |  4 +--
 indra/newview/llpanelobject.cpp         | 36 ++++++++++++++++++++-----
 indra/newview/llpanelobject.h           |  8 ++++++
 indra/newview/lltoolgrab.cpp            |  4 +--
 indra/newview/llworld.cpp               | 30 ++++++++++++++++++++-
 indra/newview/llworld.h                 | 16 ++++++++++-
 12 files changed, 123 insertions(+), 30 deletions(-)

diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index a1851a97ea..6cff01fff5 100755
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -59,7 +59,7 @@
 const F32 MIN_CUT_DELTA = 0.02f;
 
 const F32 HOLLOW_MIN = 0.f;
-const F32 HOLLOW_MAX = 0.95f;
+const F32 HOLLOW_MAX = 0.99f;
 const F32 HOLLOW_MAX_SQUARE	= 0.7f;
 
 const F32 TWIST_MIN = -1.f;
@@ -68,10 +68,10 @@ const F32 TWIST_MAX =  1.f;
 const F32 RATIO_MIN = 0.f;
 const F32 RATIO_MAX = 2.f; // Tom Y: Inverted sense here: 0 = top taper, 2 = bottom taper
 
-const F32 HOLE_X_MIN= 0.05f;
+const F32 HOLE_X_MIN= 0.01f;
 const F32 HOLE_X_MAX= 1.0f;
 
-const F32 HOLE_Y_MIN= 0.05f;
+const F32 HOLE_Y_MIN= 0.01f;
 const F32 HOLE_Y_MAX= 0.5f;
 
 const F32 SHEAR_MIN = -0.5f;
diff --git a/indra/llmath/xform.h b/indra/llmath/xform.h
index 54b0f6d9ec..90d7cf1257 100755
--- a/indra/llmath/xform.h
+++ b/indra/llmath/xform.h
@@ -30,13 +30,17 @@
 #include "m4math.h"
 #include "llquaternion.h"
 
-const F32 MAX_OBJECT_Z 		= 4096.f; // should match REGION_HEIGHT_METERS, Pre-havok4: 768.f
+const F32 SL_MAX_OBJECT_Z 	= 4096.f; // should match REGION_HEIGHT_METERS, Pre-havok4: 768.f
+const F32 OS_MAX_OBJECT_Z	= 10000.f;
 const F32 MIN_OBJECT_Z 		= -256.f;
-const F32 DEFAULT_MAX_PRIM_SCALE = 64.f;
-const F32 DEFAULT_MAX_PRIM_SCALE_NO_MESH = 10.f;
-const F32 MIN_PRIM_SCALE = 0.01f;
+const F32 SL_DEFAULT_MAX_PRIM_SCALE = 64.f;
+const F32 OS_DEFAULT_MAX_PRIM_SCALE = 256.f;
+const F32 SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH = 10.f;
+const F32 SL_MIN_PRIM_SCALE = 0.01f;
+const F32 OS_MIN_PRIM_SCALE = 0.001f;
 const F32 MAX_PRIM_SCALE = 65536.f;	// something very high but not near FLT_MAX
 
+
 class LLXform
 {
 protected:
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index 29747cb09c..5a6d212a8e 100755
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -60,10 +60,14 @@ const F32 OBJECT_TWIST_LINEAR_MIN	= -180.f;
 const F32 OBJECT_TWIST_LINEAR_MAX	=  180.f;
 const F32 OBJECT_TWIST_LINEAR_INC	=    9.f;
 
-const F32 OBJECT_MIN_HOLE_SIZE = 0.05f;
+const F32 SL_OBJECT_MIN_HOLE_SIZE = 0.05f;
+const F32 OS_OBJECT_MIN_HOLE_SIZE = 0.01f;
 const F32 OBJECT_MAX_HOLE_SIZE_X = 1.0f;
 const F32 OBJECT_MAX_HOLE_SIZE_Y = 0.5f;
 
+const F32 SL_OBJECT_MAX_HOLLOW_SIZE = 95.f;
+const F32 OS_OBJECT_MAX_HOLLOW_SIZE = 99.f;
+
 // Revolutions parameters.
 const F32 OBJECT_REV_MIN = 1.0f;
 const F32 OBJECT_REV_MAX = 4.0f;
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 1bf83e36b4..85ce61afee 100755
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -80,10 +80,14 @@ extern const F32 OBJECT_TWIST_LINEAR_MIN;
 extern const F32 OBJECT_TWIST_LINEAR_MAX;
 extern const F32 OBJECT_TWIST_LINEAR_INC;
 
-extern const F32 OBJECT_MIN_HOLE_SIZE;
+extern const F32 SL_OBJECT_MIN_HOLE_SIZE;
+extern const F32 OS_OBJECT_MIN_HOLE_SIZE;
 extern const F32 OBJECT_MAX_HOLE_SIZE_X;
 extern const F32 OBJECT_MAX_HOLE_SIZE_Y;
 
+extern const F32 SL_OBJECT_MAX_HOLLOW_SIZE;
+extern const F32 OS_OBJECT_MAX_HOLLOW_SIZE;
+
 // Revolutions parameters.
 extern const F32 OBJECT_REV_MIN;
 extern const F32 OBJECT_REV_MAX;
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index f2f3be3022..bd08c9cfe0 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -98,6 +98,7 @@
 #include "lltoggleablemenu.h"
 #include "lltrans.h"
 #include "llvfile.h"
+#include "llworld.h" // for getRegionMaxPrimScale()
 #include "llvfs.h"
 #include "llcallbacklist.h"
 #include "llviewerobjectlist.h"
@@ -3428,7 +3429,7 @@ void LLModelPreview::rebuildUploadData()
 		}
 	}
 
-	F32 max_import_scale = (DEFAULT_MAX_PRIM_SCALE-0.1f)/max_scale;
+	F32 max_import_scale = LLWorld::getInstance()->getRegionMaxPrimScale() / max_scale;
 
 	F32 max_axis = llmax(mPreviewScale.mV[0], mPreviewScale.mV[1]);
 	max_axis = llmax(max_axis, mPreviewScale.mV[2]);
diff --git a/indra/newview/llmanipscale.cpp b/indra/newview/llmanipscale.cpp
index 94862c2a54..22c6795026 100755
--- a/indra/newview/llmanipscale.cpp
+++ b/indra/newview/llmanipscale.cpp
@@ -92,11 +92,11 @@ F32 get_default_max_prim_scale(bool is_flora)
 	if (gMeshRepo.meshRezEnabled() &&
 		!is_flora)
 	{
-		return DEFAULT_MAX_PRIM_SCALE;
+		return LLWorld::getInstance()->getRegionMaxPrimScale();
 	}
 	else
 	{
-		return DEFAULT_MAX_PRIM_SCALE_NO_MESH;
+		return LLWorld::getInstance()->getRegionMaxPrimScaleNoMesh();
 	}
 }
 
@@ -919,8 +919,8 @@ void LLManipScale::dragCorner( S32 x, S32 y )
 	}
 
 
-	F32 max_scale_factor = get_default_max_prim_scale() / MIN_PRIM_SCALE;
-	F32 min_scale_factor = MIN_PRIM_SCALE / get_default_max_prim_scale();
+	F32 max_scale_factor = LLWorld::getInstance()->getRegionMaxPrimScale() / LLWorld::getInstance()->getRegionMinPrimScale();
+	F32 min_scale_factor = LLWorld::getInstance()->getRegionMinPrimScale() / LLWorld::getInstance()->getRegionMaxPrimScale();
 
 	// find max and min scale factors that will make biggest object hit max absolute scale and smallest object hit min absolute scale
 	for (LLObjectSelection::iterator iter = mObjectSelection->begin();
@@ -935,10 +935,16 @@ void LLManipScale::dragCorner( S32 x, S32 y )
 		{
 			const LLVector3& scale = selectNode->mSavedScale;
 
-			F32 cur_max_scale_factor = llmin( get_default_max_prim_scale(LLPickInfo::isFlora(cur)) / scale.mV[VX], get_default_max_prim_scale(LLPickInfo::isFlora(cur)) / scale.mV[VY], get_default_max_prim_scale(LLPickInfo::isFlora(cur)) / scale.mV[VZ] );
+			F32 cur_max_scale_factor = llmin( get_default_max_prim_scale(LLPickInfo::isFlora(cur))
+											 / scale.mV[VX], get_default_max_prim_scale(LLPickInfo::isFlora(cur))
+											 / scale.mV[VY], get_default_max_prim_scale(LLPickInfo::isFlora(cur))
+											 / scale.mV[VZ] );
 			max_scale_factor = llmin( max_scale_factor, cur_max_scale_factor );
 
-			F32 cur_min_scale_factor = llmax( MIN_PRIM_SCALE / scale.mV[VX], MIN_PRIM_SCALE / scale.mV[VY], MIN_PRIM_SCALE / scale.mV[VZ] );
+			F32 cur_min_scale_factor = llmax( LLWorld::getInstance()->getRegionMinPrimScale()
+											 / scale.mV[VX], LLWorld::getInstance()->getRegionMinPrimScale()
+											 / scale.mV[VY], LLWorld::getInstance()->getRegionMinPrimScale()
+											 / scale.mV[VZ] );
 			min_scale_factor = llmax( min_scale_factor, cur_min_scale_factor );
 		}
 	}
@@ -1231,7 +1237,7 @@ void LLManipScale::stretchFace( const LLVector3& drag_start_agent, const LLVecto
 
 			F32 denom = axis * dir_local;
 			F32 desired_delta_size	= is_approx_zero(denom) ? 0.f : (delta_local_mag / denom);  // in meters
-			F32 desired_scale		= llclamp(selectNode->mSavedScale.mV[axis_index] + desired_delta_size, MIN_PRIM_SCALE, get_default_max_prim_scale(LLPickInfo::isFlora(cur)));
+			F32 desired_scale		= llclamp(selectNode->mSavedScale.mV[axis_index] + desired_delta_size, LLWorld::getInstance()->getRegionMinPrimScale(), get_default_max_prim_scale(LLPickInfo::isFlora(cur)));
 			// propagate scale constraint back to position offset
 			desired_delta_size		= desired_scale - selectNode->mSavedScale.mV[axis_index]; // propagate constraint back to position
 
@@ -2019,7 +2025,7 @@ F32		LLManipScale::partToMinScale( S32 part, const LLBBox &bbox ) const
 			min_extent = bbox_extents.mV[i];
 		}
 	}
-	F32 min_scale_factor = bbox_extents.length() * MIN_PRIM_SCALE / min_extent;
+	F32 min_scale_factor = bbox_extents.magVec() * LLWorld::getInstance()->getRegionMinPrimScale() / min_extent;
 
 	if (getUniform())
 	{
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp
index 47324a638f..e57beddfd0 100755
--- a/indra/newview/llmaniptranslate.cpp
+++ b/indra/newview/llmaniptranslate.cpp
@@ -726,9 +726,9 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask)
 				}
 
 				// For safety, cap heights where objects can be dragged
-				if (new_position_global.mdV[VZ] > MAX_OBJECT_Z)
+				if (new_position_global.mdV[VZ] > LLWorld::getInstance()->getRegionMaxHeight())
 				{
-					new_position_global.mdV[VZ] = MAX_OBJECT_Z;
+					new_position_global.mdV[VZ] = LLWorld::getInstance()->getRegionMaxHeight();
 				}
 
 				// Grass is always drawn on the ground, so clamp its position to the ground
diff --git a/indra/newview/llpanelobject.cpp b/indra/newview/llpanelobject.cpp
index b46dce03cb..22d0fcce37 100755
--- a/indra/newview/llpanelobject.cpp
+++ b/indra/newview/llpanelobject.cpp
@@ -302,7 +302,8 @@ LLPanelObject::LLPanelObject()
 	mSelectedType(MI_BOX),
 	mSculptTextureRevert(LLUUID::null),
 	mSculptTypeRevert(0),
-	mSizeChanged(FALSE)
+	mSizeChanged(FALSE),
+	mUpdateLimits(true)
 {
 	mCommitCallbackRegistrar.add("Build.Copy", boost::bind(&LLPanelObject::onClickBtnCopyData, this, _2));
 	mCommitCallbackRegistrar.add("Build.Paste", boost::bind(&LLPanelObject::onClickBtnPasteData, this, _2));
@@ -942,9 +943,9 @@ void LLPanelObject::getState( )
 		mSpinScaleY->set( scale_y );
 		calcp->setVar(LLCalc::X_HOLE, scale_x);
 		calcp->setVar(LLCalc::Y_HOLE, scale_y);
-		mSpinScaleX->setMinValue(OBJECT_MIN_HOLE_SIZE);
+		mSpinScaleX->setMinValue(mMinHoleSize);
 		mSpinScaleX->setMaxValue(OBJECT_MAX_HOLE_SIZE_X);
-		mSpinScaleY->setMinValue(OBJECT_MIN_HOLE_SIZE);
+		mSpinScaleY->setMinValue(mMinHoleSize);
 		mSpinScaleY->setMaxValue(OBJECT_MAX_HOLE_SIZE_Y);
 		break;
 	default:
@@ -980,7 +981,7 @@ void LLPanelObject::getState( )
 	else 
 	{
 		mSpinHollow->setMinValue(0.f);
-		mSpinHollow->setMaxValue(100.f); // <alchemy/>
+		mSpinHollow->setMaxValue(mMaxHollowSize);
 	}
 
 	// Update field enablement
@@ -1511,11 +1512,11 @@ void LLPanelObject::getVolumeParams(LLVolumeParams& volume_params)
 	{
 		scale_x = llclamp(
 			scale_x,
-			OBJECT_MIN_HOLE_SIZE,
+			mMinHoleSize,
 			OBJECT_MAX_HOLE_SIZE_X);
 		scale_y = llclamp(
 			scale_y,
-			OBJECT_MIN_HOLE_SIZE,
+			mMinHoleSize,
 			OBJECT_MAX_HOLE_SIZE_Y);
 
 		// Limit radius offset, based on taper and hole size y.
@@ -1838,6 +1839,9 @@ void LLPanelObject::sendSculpt()
 
 void LLPanelObject::refresh()
 {
+	if (mUpdateLimits)
+		refreshLimits();
+	
 	getState();
 	if (mObject.notNull() && mObject->isDead())
 	{
@@ -1856,6 +1860,26 @@ void LLPanelObject::refresh()
 	getChild<LLSpinCtrl>("Scale Z")->setMaxValue(max_scale);
 }
 
+void LLPanelObject::refreshLimits()
+{
+	mUpdateLimits = false;
+
+	mRegionMaxHeight = LLWorld::getInstance()->getRegionMaxHeight();
+	mCtrlPosZ->setMaxValue(mRegionMaxHeight);
+	mMinScale = LLWorld::getInstance()->getRegionMinPrimScale();
+	mMaxScale = LLWorld::getInstance()->getRegionMaxPrimScale();
+	mCtrlScaleX->setMinValue(mMinScale);
+	mCtrlScaleX->setMaxValue(mMaxScale);
+	mCtrlScaleY->setMinValue(mMinScale);
+	mCtrlScaleY->setMaxValue(mMaxScale);
+	mCtrlScaleZ->setMinValue(mMinScale);
+	mCtrlScaleZ->setMaxValue(mMaxScale);
+	mMaxHollowSize = LLWorld::getInstance()->getRegionMaxHollowSize();
+	mSpinHollow->setMaxValue(mMaxHollowSize);
+	mMinHoleSize = LLWorld::getInstance()->getRegionMinHoleSize();
+	mSpinScaleX->setMinValue(mMinHoleSize);
+	mSpinScaleY->setMinValue(mMinHoleSize);
+}
 
 void LLPanelObject::draw()
 {
diff --git a/indra/newview/llpanelobject.h b/indra/newview/llpanelobject.h
index daa90d06fb..a52d8a0f3c 100755
--- a/indra/newview/llpanelobject.h
+++ b/indra/newview/llpanelobject.h
@@ -55,6 +55,7 @@ public:
 	virtual void 	clearCtrls();
 
 	void			refresh();
+	void			refreshLimits();
 
 	static bool		precommitValidate(const LLSD& data);
 	
@@ -177,6 +178,13 @@ protected:
 
 	LLUUID          mSculptTextureRevert;   // so we can revert the sculpt texture on cancel
 	U8              mSculptTypeRevert;      // so we can revert the sculpt type on cancel
+	
+	F32				mRegionMaxHeight;
+	F32				mMinScale;
+	F32				mMaxScale;
+	F32				mMaxHollowSize;
+	F32				mMinHoleSize;
+	bool			mUpdateLimits;
 
 	LLSD			mCopiedObjectData;
 
diff --git a/indra/newview/lltoolgrab.cpp b/indra/newview/lltoolgrab.cpp
index 4452b06cbe..7602254362 100755
--- a/indra/newview/lltoolgrab.cpp
+++ b/indra/newview/lltoolgrab.cpp
@@ -623,9 +623,9 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
 			}
 
 			// For safety, cap heights where objects can be dragged
-			if (grab_point_global.mdV[VZ] > MAX_OBJECT_Z)
+			if (grab_point_global.mdV[VZ] > LLWorld::getInstance()->getRegionMaxHeight())
 			{
-				grab_point_global.mdV[VZ] = MAX_OBJECT_Z;
+				grab_point_global.mdV[VZ] = LLWorld::getInstance()->getRegionMaxHeight();
 			}
 
 			grab_point_global = LLWorld::getInstance()->clipToVisibleRegions(mDragStartPointGlobal, grab_point_global);
diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp
index 361015305c..27cc25b7e4 100755
--- a/indra/newview/llworld.cpp
+++ b/indra/newview/llworld.cpp
@@ -92,7 +92,8 @@ LLWorld::LLWorld() :
 	mLastPacketsIn(0),
 	mLastPacketsOut(0),
 	mLastPacketsLost(0),
-	mSpaceTimeUSec(0)
+	mSpaceTimeUSec(0),
+	mRefreshLimits(true)
 {
 	for (S32 i = 0; i < 8; i++)
 	{
@@ -277,6 +278,9 @@ LLViewerRegion* LLWorld::addRegion(const U64 &region_handle, const LLHost &host)
 	}
 
 	updateWaterObjects();
+	
+	if (mRefreshLimits)
+		refreshLimits();
 
 	return regionp;
 }
@@ -791,6 +795,30 @@ void LLWorld::clearAllVisibleObjects()
 	}
 }
 
+void LLWorld::refreshLimits()
+{
+	mRefreshLimits = false;
+
+	if (LLGridManager::getInstance()->isInOpenSim())
+	{
+		mRegionMaxHeight = OS_MAX_OBJECT_Z; //llmath/xform.h
+		mRegionMinPrimScale = OS_MIN_PRIM_SCALE;
+		mRegionMaxPrimScale = OS_DEFAULT_MAX_PRIM_SCALE;
+		mRegionMaxPrimScaleNoMesh = OS_DEFAULT_MAX_PRIM_SCALE; // no restrictions here
+		mRegionMaxHollowSize = OS_OBJECT_MAX_HOLLOW_SIZE;
+		mRegionMinHoleSize = OS_OBJECT_MIN_HOLE_SIZE;
+	}
+	else
+	{
+		mRegionMaxHeight = SL_MAX_OBJECT_Z;
+		mRegionMinPrimScale = SL_MIN_PRIM_SCALE;
+		mRegionMaxPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
+		mRegionMaxPrimScaleNoMesh = SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH;
+		mRegionMaxHollowSize = SL_OBJECT_MAX_HOLLOW_SIZE;
+		mRegionMinHoleSize = SL_OBJECT_MIN_HOLE_SIZE;
+	}
+}
+
 void LLWorld::updateParticles()
 {
 	LLViewerPartSim::getInstance()->updateSimulation();
diff --git a/indra/newview/llworld.h b/indra/newview/llworld.h
index d7b082f761..d0e19d0c60 100755
--- a/indra/newview/llworld.h
+++ b/indra/newview/llworld.h
@@ -115,7 +115,12 @@ public:
 	// region X and Y size in meters
 	F32						getRegionWidthInMeters() const	{ return mWidthInMeters; }
 	F32						getRegionMinHeight() const		{ return -mWidthInMeters; }
-	F32						getRegionMaxHeight() const		{ return MAX_OBJECT_Z; }
+	F32						getRegionMaxHeight() const		{ return mRegionMaxHeight; }
+	F32						getRegionMinPrimScale() const	{ return mRegionMinPrimScale; }
+	F32						getRegionMaxPrimScale() const	{ return mRegionMaxPrimScale; }
+	F32						getRegionMaxPrimScaleNoMesh() const	{ return mRegionMaxPrimScaleNoMesh; }
+	F32						getRegionMaxHollowSize() const	{ return mRegionMaxHollowSize; }
+	F32						getRegionMinHoleSize() const	{ return mRegionMinHoleSize; }
 
 	void					updateRegions(F32 max_update_time);
 	void					updateVisibilities();
@@ -149,6 +154,8 @@ public:
 	U32  getNumOfActiveCachedObjects() const {return mNumOfActiveCachedObjects;}
 
 	void clearAllVisibleObjects();
+	void refreshLimits();
+	
 public:
 	typedef std::list<LLViewerRegion*> region_list_t;
 	const region_list_t& getRegionList() const { return mActiveRegionList; }
@@ -190,6 +197,13 @@ private:
 	static const F32 mScale;
 
 	static F32 mWidthInMeters;
+	F32 mRegionMaxHeight;
+	F32 mRegionMinPrimScale;
+	F32 mRegionMaxPrimScale;
+	F32 mRegionMaxPrimScaleNoMesh;
+	F32 mRegionMaxHollowSize;
+	F32 mRegionMinHoleSize;
+	bool mRefreshLimits;
 
 	F32 mLandFarClip;					// Far clip distance for land.
 	LLPatchVertexArray		mLandPatch;
-- 
GitLab